Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 325
fix: avoid possible job already exists error#751
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3190,6 +3190,7 @@ def query( | ||
| If ``job_config`` is not an instance of :class:`~google.cloud.bigquery.job.QueryJobConfig` | ||
| class. | ||
| """ | ||
| job_id_given = job_id is not None | ||
| job_id = _make_job_id(job_id, job_id_prefix) | ||
| if project is None: | ||
| @@ -3221,9 +3222,30 @@ def query( | ||
| job_ref = job._JobReference(job_id, project=project, location=location) | ||
| query_job = job.QueryJob(job_ref, query, client=self, job_config=job_config) | ||
| query_job._begin(retry=retry, timeout=timeout) | ||
| return query_job | ||
| try: | ||
| query_job._begin(retry=retry, timeout=timeout) | ||
| except core_exceptions.Conflict as create_exc: | ||
| # The thought is if someone is providing their own job IDs and they get | ||
| # their job ID generation wrong, this could end up returning results for | ||
| # the wrong query. We thus only try to recover if job ID was not given. | ||
| if job_id_given: | ||
| raise create_exc | ||
| try: | ||
| query_job = self.get_job( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, there is a slight problem with this change - self.get_job has a different return type to this function. It can return LoadJob, etc as well as the QueryJob we're expecting so the actual return type doesn't match what is declared for this function. I don't understand the situations that could result in this code being called, but presumably in reality this would always be a QueryJob? Unfortunately this is causing me problems when running pylint over some code that calls this, because it thinks the function can return LoadJob, and that has a different set of members to QueryJob. Many thanks, ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, in this context This project uses Could you tell There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having looked into this a bit further I agree that pylint is wrong. It's a bit of a pain to have disable this check every time we call query, but I think this is a sign that pylint is aging and not keeping up with modern Python's type syntax. Sorry for the noise. Cheers, ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, it was a perfectly valid comment. Ideally,
| ||
| job_id, | ||
| project=project, | ||
| location=location, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| ) | ||
| except core_exceptions.GoogleAPIError: # (includes RetryError) | ||
| raise create_exc | ||
| else: | ||
| return query_job | ||
| else: | ||
| return query_job | ||
| def insert_rows( | ||
| self, | ||
Uh oh!
There was an error while loading. Please reload this page.