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: QueryJob.exception() *returns* the errors, not raises them by plamut · Pull Request #467 · googleapis/python-bigquery

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

Conversation

@plamut

@plamut plamut commented Jan 12, 2021

Copy link
Copy Markdown
Contributor

Fixes #451.

This PR makes sure that QueryJob.exception() actually returns exceptions as documented, not raises them.

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: QueryJob.exception() should *return* errors
a85fe8f
@plamut
plamut requested review from a team and tswast January 12, 2021 12:26
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jan 12, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jan 12, 2021
plamut
plamut commented Jan 12, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

@plamut
Reload query job on error, raise any reload errors
07af774
plamut
plamut commented Jan 13, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

plamut
plamut commented Jan 13, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

tswast
tswast suggested changes Jan 22, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

tswast
tswast approved these changes Jan 25, 2021
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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.

Thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast suggested changes Jan 25, 2021
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

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.

Retracting approval until

Or can we call set_exception and return False in this case? We'd want a unit test that confirms result() doesn't get into an infinite loop.

is handled.

Sorry, something went wrong.

Uh oh!

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

All reactions
plamut added 2 commits January 25, 2021 18:06
@plamut
Merge branch 'master' into iss-451
7d9a7e8
@plamut
Catch errors on reloading failed query jobs
a19f07e
@plamut plamut added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 27, 2021
@plamut
Add additional unit test
f3ddc14
@plamut plamut removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 27, 2021
@plamut
plamut requested a review from tswast January 27, 2021 15:21
@plamut

plamut commented Jan 27, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Hmm, TestQueryJob.test_result_w_retry seems to be flaky (failed run).

oogle.api_core.exceptions.RetryError: Deadline of 0.0s exceeded while calling functools.partial(functools.partial(<MagicMock name='mock.api_request' spec='function' id='140372364135632'>, method='GET', path='/projects/project/jobs/JOB_ID', query_params={}, timeout=None))

The same test passed with Python 3.6, 3.8, and also locally - let's see if the results are consistent on a re-run.

All reactions

Sorry, something went wrong.

Uh oh!

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

@plamut plamut added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 27, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 27, 2021
plamut
plamut commented Jan 27, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

@plamut plamut added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 27, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 28, 2021
@plamut
Increase retry deadline to mitigate test flakiness
ef2fe8e
@plamut
plamut force-pushed the iss-451 branch from 7654e8d to ef2fe8e Compare January 28, 2021 13:04
@plamut

plamut commented Jan 28, 2021

Copy link
Copy Markdown
Contributor Author

I was able to reproduce flakiness on my machine by reducing the retry deadline in affected tests by ~25 %, which means the latter was indeed the culprit. Because done() now does a bit of extra work, it appears that was just enough of a slowdown to start causing the failures (at least under Python 3.7).

Although not ideal, increasing the deadline should be a solution sufficient with high enough probability.

All reactions

Sorry, something went wrong.

Uh oh!

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

tswast
tswast reviewed Feb 2, 2021
View reviewed changes
Comment thread google/cloud/bigquery/job/query.py Resolved

Uh oh!

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

Comment thread tests/unit/job/test_query.py
is_done = job.done()

assert is_done
assert isinstance(job._exception, exceptions.BadRequest)

@tswast tswast Feb 2, 2021

Copy link
Copy Markdown
Contributor

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.

why use the private property in this and the other tests? any objections to calling job.exception() here and the other tests?

Sorry, something went wrong.

Uh oh!

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

All reactions

@plamut plamut Feb 23, 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.

The reasoning was that job.exception() can execute additional logic, and errors in that method would make the tests for done() fail, too, even if there was nothing wrong with the done() method itself.

One could argue that the chosen unit of test is too small, and that the class itself should represent a unit as opposed to its individual methods, but addressing that would require quite some refactoring (we already tinker with internal _properties , for instance).

Here, practicality beats purity IMHO, thus the "cheating" by examining the internal state of the class. Or do you have a strong opinion on this?

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Feb 25, 2021

Copy link
Copy Markdown
Contributor

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.

Works for me. I agree that ideally we'd have higher-level tests than this, but makes sense to stay with existing conventions, especially given our 100% coverage requirement.

Sorry, something went wrong.

Uh oh!

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

All reactions
plamut added 2 commits February 23, 2021 13:30
@plamut
Merge branch 'master' into iss-451
56c4e96
@plamut
Store the more informative exception in done()
739627a
@plamut
plamut requested a review from tswast February 23, 2021 13:44
tswast
tswast approved these changes Feb 25, 2021
View reviewed changes
Comment thread tests/unit/job/test_query.py
is_done = job.done()

assert is_done
assert isinstance(job._exception, exceptions.BadRequest)

@tswast tswast Feb 25, 2021

Copy link
Copy Markdown
Contributor

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.

Works for me. I agree that ideally we'd have higher-level tests than this, but makes sense to stay with existing conventions, especially given our 100% coverage requirement.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast
tswast merged commit d763279 into googleapis:master Feb 25, 2021
gcf-merge-on-green Bot pushed a commit that referenced this pull request Feb 25, 2021
@release-please
chore: release 2.10.0 (#533)
81df4ba
🤖 I have created a release \*beep\* \*boop\* 
---
## [2.10.0](https://www.github.com/googleapis/python-bigquery/compare/v2.9.0...v2.10.0) (2021-02-25)


### Features

* add BIGNUMERIC support ([#527](https://www.github.com/googleapis/python-bigquery/issues/527)) ([cc3394f](https://www.github.com/googleapis/python-bigquery/commit/cc3394f80934419eb00c2029bb81c92a696e7d88))


### Bug Fixes

* error using empty array of structs parameter ([#474](https://www.github.com/googleapis/python-bigquery/issues/474)) ([c1d15f4](https://www.github.com/googleapis/python-bigquery/commit/c1d15f4e5da4b7e10c00afffd59a5c7f3ded027a))
* QueryJob.exception() *returns* the errors, not raises them ([#467](https://www.github.com/googleapis/python-bigquery/issues/467)) ([d763279](https://www.github.com/googleapis/python-bigquery/commit/d7632799769248b09a8558ba18f5025ebdd9675a))


### Documentation

* **bigquery:** Add alternative approach to setting credentials ([#517](https://www.github.com/googleapis/python-bigquery/issues/517)) ([60fbf28](https://www.github.com/googleapis/python-bigquery/commit/60fbf287b0d34d5db2e61cce7a5b42735ed43d0e))
* explain retry behavior for DONE jobs ([#532](https://www.github.com/googleapis/python-bigquery/issues/532)) ([696c443](https://www.github.com/googleapis/python-bigquery/commit/696c443f0a6740be0767e12b706a7771bc1460c3))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@plamut
plamut deleted the iss-451 branch February 25, 2021 19:45
This was referenced Mar 10, 2021
Bump google-cloud-bigquery from 2.9.0 to 2.11.0 in /ps2bq braincow/gcp-cloudfunctions#25
Merged
Bump google-cloud-bigquery from 2.9.0 to 2.11.0 in /ruuvitag_latest braincow/gcp-cloudfunctions#26
Merged
Bump google-cloud-bigquery from 2.9.0 to 2.11.0 in /ruuvitag_trend braincow/gcp-cloudfunctions#27
Merged
Bump google-cloud-bigquery from 2.9.0 to 2.11.0 in /ruuvitags braincow/gcp-cloudfunctions#28
Merged
Bump google-cloud-bigquery from 1.27.2 to 2.11.0 in /requirements mozilla-releng/buildhub2#750
Closed
@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

1 more reviewer
@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.

google.cloud.bigquery.job.QueryJob.exception has wrong behavior

Uh oh!

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

3 participants

@plamut @tswast @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.