GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: avoid possible job already exists error by plamut · Pull Request #751 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@plamut

@plamut plamut commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

Fixes #738.

If job create request fails, a query job might still have started successfully. This PR handles this edge case and returns such
query job one can be found.

Based on the similar fix in the Java client.

PR checklist:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plamut
fix: avoid possible job already exists error
1e4e043
If job create request fails, a query job might still have started
successfully. This commit handles this edge case and returns such
query job one can be found.
@plamut
plamut requested review from a team and tswast July 12, 2021 09:32
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jul 12, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 12, 2021
tseaver
tseaver reviewed Jul 12, 2021
View reviewed changes
Comment thread google/cloud/bigquery/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/bigquery/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@plamut

plamut commented Jul 12, 2021

Copy link
Copy Markdown
Contributor Author

@tseaver I don't know the exact mechanics on the backend, this fix is mostly based on a similar fix in the Java client.

@tswast Can you chime in?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plamut
Catch only Conflict errors on query job create
2b1a8b5
@plamut

plamut commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The docs check failure does not seem to be related:

gpg: keyserver receive failed: No name

Update: Indeed, but the fix is on its way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver approved these changes Jul 14, 2021
View reviewed changes
@plamut plamut added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 14, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 14, 2021
@tseaver

tseaver commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

googleapis/synthtool#1155 landed here in #762. I'm not sure why the config isn't making you merge with master to pick that fix up, however.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tswast
tswast approved these changes Jul 14, 2021
View reviewed changes
@tswast
tswast merged commit 45b9308 into googleapis:master Jul 14, 2021
@plamut
plamut deleted the iss-738 branch July 14, 2021 19:21
gcf-merge-on-green Bot pushed a commit that referenced this pull request Jul 19, 2021
@release-please
chore: release 2.22.0 (#771)
5802092
🤖 I have created a release \*beep\* \*boop\*
---
## [2.22.0](https://www.github.com/googleapis/python-bigquery/compare/v2.21.0...v2.22.0) (2021-07-19)


### Features

* add `LoadJobConfig.projection_fields` to select DATASTORE_BACKUP fields ([#736](https://www.github.com/googleapis/python-bigquery/issues/736)) ([c45a738](https://www.github.com/googleapis/python-bigquery/commit/c45a7380871af3dfbd3c45524cb606c60e1a01d1))
* add standard sql table type, update scalar type enums ([#777](https://www.github.com/googleapis/python-bigquery/issues/777)) ([b8b5433](https://www.github.com/googleapis/python-bigquery/commit/b8b5433898ec881f8da1303614780a660d94733a))
* add support for more detailed DML stats ([#758](https://www.github.com/googleapis/python-bigquery/issues/758)) ([36fe86f](https://www.github.com/googleapis/python-bigquery/commit/36fe86f41c1a8f46167284f752a6d6bbf886a04b))
* add support for user defined Table View Functions ([#724](https://www.github.com/googleapis/python-bigquery/issues/724)) ([8c7b839](https://www.github.com/googleapis/python-bigquery/commit/8c7b839a6ac1491c1c3b6b0e8755f4b70ed72ee3))


### Bug Fixes

* avoid possible job already exists error ([#751](https://www.github.com/googleapis/python-bigquery/issues/751)) ([45b9308](https://www.github.com/googleapis/python-bigquery/commit/45b93089f5398740413104285cc8acfd5ebc9c08))


### Dependencies

* allow 2.x versions of `google-api-core`, `google-cloud-core`, `google-resumable-media` ([#770](https://www.github.com/googleapis/python-bigquery/issues/770)) ([87a09fa](https://www.github.com/googleapis/python-bigquery/commit/87a09fa3f2a9ab35728a1ac925f9d5f2e6616c65))


### Documentation

* add loading data from Firestore backup sample ([#737](https://www.github.com/googleapis/python-bigquery/issues/737)) ([22fd848](https://www.github.com/googleapis/python-bigquery/commit/22fd848cae4af1148040e1faa31dd15a4d674687))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
andrewjw
andrewjw reviewed Jul 26, 2021
View reviewed changes
Comment thread google/cloud/bigquery/client.py
raise create_exc

try:
query_job = self.get_job(

@andrewjw andrewjw Jul 26, 2021

Copy link
Copy Markdown

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@plamut plamut Jul 26, 2021

Copy link
Copy Markdown
Contributor Author

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 a QueryJob, because job_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 apparently pylint could not deduce the same and reported a false issue.

Could you tell pylint to ignore return type in that specific line where query() is called? IMHO that justifiable, because pylint is wrong there.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewjw andrewjw Jul 27, 2021

Copy link
Copy Markdown

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@plamut plamut Jul 27, 2021

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewjw andrewjw Jul 27, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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 accessing num_dml_affected_rows, which only exists on QueryJob, and not on LoadJob. 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 from google.api_core.future.polling.PollingFuture. The problem is that google.api_core.future.polling.PollingFuture is not typable, so it gets turns into an Any 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 the PollingFuture import line explicitly, but I guess pytype 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 an assert isinstance(query_job, job.QueryJob) will resolve the issue.

Cheers,
Andrew
invalid_return_union.txt

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release python-bigquery 1.27.1 #1097
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@andrewjw andrewjw andrewjw left review comments
@tseaver tseaver tseaver approved these changes
@tswast tswast tswast approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Job already exists

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@plamut @tseaver @tswast @andrewjw @yoshi-kokoro
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.