-
Notifications
You must be signed in to change notification settings - Fork 323
fix: avoid possible job already exists error #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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, 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, 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, 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. Sadly the error isn't raised on the call to It's been bugging me why this wouldn't be picked up by the type checker. I think I've tracked it down to the fact that I've create the attached file demonstrating the problem (annoyingly github won't let me attach the file as a .py). As currently written it'll generate an error in both mypy and pytype, but swap the comments on lines 5 and 6 and the error goes away. Anyway, I have a reasonable workaround, so if you want to leave this that's absolutely fine. If in future the Cheers, |
||
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.