Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix: avoid possible job already exists error #751
fix: avoid possible job already exists error #751
Changes from all commits
1e4e043
2b1a8b5
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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,
Andrew Wilkinson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, in this context
self.get_job()
returns aQueryJob
, becausejob_id
is the same ID that was used a few lines above when constructing a new query job (and then starting it).This project uses
pytype
for static type checks and it did not complain, but apparentlypylint
could not deduce the same and reported a false issue.Could you tell
pylint
to ignore return type in that specific line wherequery()
is called? IMHO that justifiable, becausepylint
is wrong there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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,
Andrew
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, it was a perfectly valid comment.
Ideally,
pylint
would allow ignoring particular warnings for lines matching a regex, but I'm not sure if that's currently supported? It would make disabling those false positives much cleaner compared to spamming the# pylint: disable=...
comments all around the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly the error isn't raised on the call to
query
, but when you try and use the return value. In my case this is accessingnum_dml_affected_rows
, which only exists onQueryJob
, and not onLoadJob
. Even if it did support disabling errors using a regex, I'm not sure it would be practical to create one.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
LoadJob
,QueryJob
, etc all derive from_AsyncJob
, which in turn derives fromgoogle.api_core.future.polling.PollingFuture
. The problem is thatgoogle.api_core.future.polling.PollingFuture
is not typable, so it gets turns into anAny
type, which makes all the job types equivalent and therefore doesn't generate an error. When testing with mypy you have to add# type: ignore
to thePollingFuture
import line explicitly, but I guesspytype
is more forgiving.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
python-api-core
library adds typing then I expect this to break though. Adding anassert isinstance(query_job, job.QueryJob)
will resolve the issue.Cheers,
Andrew
invalid_return_union.txt