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: retry 404 errors in `Client.query(...)` by tswast · Pull Request #2135 · googleapis/python-bigquery

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

Conversation

@tswast

@tswast tswast commented Feb 18, 2025

Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • 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)

Fixes #2134 🦕

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast
fix: retry 404 errors in Client.query(...)
eb09d8f
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery API. labels Feb 18, 2025
@tswast
retry on 404
0138de5
@tswast
tswast marked this pull request as ready for review February 18, 2025 23:11
@tswast
tswast requested review from a team and Neenu1995 February 18, 2025 23:11
@blunderbuss-gcf blunderbuss-gcf Bot assigned chalmerlowe Feb 18, 2025
tswast
tswast commented Feb 18, 2025
View reviewed changes
Comment thread google/cloud/bigquery/_job_helpers.py Outdated
if job_retry is None:
future = do_query()
else:
future = job_retry(do_query)()

@tswast tswast Feb 18, 2025

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.

Note: even though I add the retry here, we'll still need the one in QueryJob, because BigQuery queries can be started successfully but still fail for a retriablle reason. By adding the retry here, we can retry the queries that fail for a retriable reason.

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast commented Feb 18, 2025
View reviewed changes
Comment thread google/cloud/bigquery/retry.py Outdated
# Per https://github.com/googleapis/python-bigquery/issues/2134, sometimes
# we get a 404 error. In this case, if we get this far, assume that the job
# doesn't actually exist and try again.
or isinstance(exc, exceptions.NotFound)

@tswast tswast Feb 18, 2025

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.

Thought: Does this make it so that the queries retry if the table is not found? Or is this only going to happen for query job not found.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Feb 18, 2025

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.

😢 It does hang / retry too much. Tested with

import google.cloud.bigquery

client = google.cloud.bigquery.Client()
job = client.query("SELECT * FROM `swast-scratch.my_dataset.doesntexistnoreally`")
job.result()

Need to play a similar trick as with get_job_retry, instead.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Feb 18, 2025

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.

Fixed in latest commit.

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast added 2 commits February 18, 2025 17:37
@tswast
only retry notfound on jobs.insert
c7a8c96
@tswast
try to improve code coverage
cbb2f03
@tswast

tswast commented Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

I confirmed with my colleague that after at pip install --upgrade git+https://github.com/googleapis/python-bigquery.git@issue2134-query404, this resolved their issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

tswast
tswast commented Feb 19, 2025
View reviewed changes
Comment thread google/cloud/bigquery/_job_helpers.py Outdated
get_job_retry = retry.with_predicate(
lambda exc: isinstance(exc, core_exceptions.NotFound)
# Reference the original retry to avoid recursion.
or retry._predicate(exc)

@tswast tswast Feb 19, 2025

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.

@parthea Do you have any thoughts on how stable this will be? I couldn't find any public way to pull out the previous predicate from a Retry object when looking at the https://github.com/googleapis/python-api-core/blob/main/google/api_core/retry/retry_base.py code.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Feb 20, 2025

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.

An alternative to consider: do something like I did with retry versus job_retry and introduce more parameters for job_insert_retry and job_get_retry or something like that.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tswast tswast Feb 20, 2025

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.

Filed https://github.com/googleapis/python-api-core/issues/796, in the meantime I'll pursue an alternative that doesn't require access to private attributes.

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast commented Feb 19, 2025
View reviewed changes
Comment thread google/cloud/bigquery/_job_helpers.py Outdated
return True

# Reference the original job_retry to avoid recursion.
return job_retry._predicate(exc)

@tswast tswast Feb 19, 2025

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.

@parthea likewise here. I ended up using a slightly different pattern here due to the double nesting of retry objects.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast

tswast commented Feb 19, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

system-3.12 failure: tests/system/test_client.py::TestBigQuery::test_load_table_from_file_w_explicit_location -- doesn't appear to be related, as that is a load job and this change only touches query jobs.

Edit: Actually, it does appear to be related. It's a different kind of 404 -- trying to query a table in a different location. I'll see if I can disambiguate that from the job 404.

Edit2: fixed in 8e20cb0. I use the message to disambiguate job not found from dataset/table not found based on the stack trace in #2134. System test passing locally (and much more quickly).

All reactions

Sorry, something went wrong.

Uh oh!

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

@tswast
disambiguate job not found from dataset/table not found
8e20cb0
@tswast

tswast commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

Kokoro (https://btx.cloud.google.com/invocations/91aed90f-987e-4200-be14-09717b48923f/targets/cloud-devrel%2Fclient-libraries%2Fpython%2Fgoogleapis%2Fpython-bigquery%2Fpresubmit%2Fpresubmit/log) and system-3.12 and snippets tests are passing. Ready for review!

All reactions

Sorry, something went wrong.

Uh oh!

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

@tswast tswast mentioned this pull request Jan 12, 2026
Retry should have a public way to access the predicate googleapis/google-cloud-python#15026
Open
tswast added 2 commits February 20, 2025 12:12
@tswast
remove use of private attributes
0e2d2a9
@tswast
fix unit tests
c0af0d0
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Feb 20, 2025
@tswast

tswast commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

Cover is failing: google/cloud/bigquery/retry.py 42 1 12 1 96% 180

I'll see if I can update a unit test for this soon.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tswast
fix cover for retry.py
189f559
@tswast

tswast commented Feb 21, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Coverage for retry.py should be fixed by 189f559

I updated the patched retry object to use the correct one. This ensures that the 404 is retried until the timeout for the retry object.

Edit: Confirmed that the kokoro job, which includes the cover nox session, is passing on this commit (logs).

All reactions

Sorry, something went wrong.

Uh oh!

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

Linchin
Linchin reviewed Feb 21, 2025
View reviewed changes
Comment thread tests/unit/test_client.py
with pytest.raises(DataLoss, match="we lost your job, sorry"):
client.query("SELECT 1;", job_id=None)

def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_fails_no_retries(self):

@Linchin Linchin Feb 21, 2025

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.

Could you help me understand what this test is for? It feels like we are just verifying that QueryJob._begin() and client.get_job() are called.

Sorry, something went wrong.

Uh oh!

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

All reactions
Linchin
Linchin approved these changes Feb 21, 2025
View reviewed changes

@Linchin Linchin 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.

Thank you, lgtm.

Sorry, something went wrong.

Uh oh!

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

All reactions
@tswast
Merge branch 'main' into issue2134-query404
8ae1213
@tswast
tswast enabled auto-merge (squash) February 26, 2025 02:02
@tswast
tswast merged commit c6d5f8a into main Feb 26, 2025
@tswast
tswast deleted the issue2134-query404 branch February 26, 2025 02:24
@release-please release-please Bot mentioned this pull request Feb 26, 2025
chore(main): release 3.30.0 #2119
Merged
This was referenced Mar 4, 2025
March 03, 2025 kitta65/bq-extension-vscode#678
Closed
March 03, 2025 kitta65/prettier-plugin-bq#614
Closed
March 03, 2025 kitta65/bq2cst#480
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@Neenu1995 Neenu1995 Awaiting requested review from Neenu1995
1 more reviewer
@Linchin Linchin Linchin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@chalmerlowe chalmerlowe

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. size: l Pull request size is large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Client.query() sometimes raises 404, despite the query job being successfully started

Uh oh!

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

3 participants

@tswast @Linchin @chalmerlowe
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.