Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: retry 404 errors inClient.query(...)#2135

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tswast merged 9 commits intomainfromissue2134-query404
Feb 26, 2025
Merged

Conversation

@tswast
Copy link
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 abug/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 🦕

@product-auto-labelproduct-auto-labelbot added size: mPull request size is medium. api: bigqueryIssues related to the googleapis/python-bigquery API. labelsFeb 18, 2025
@tswasttswast marked this pull request as ready for reviewFebruary 18, 2025 23:11
@tswasttswast requested review froma team ascode ownersFebruary 18, 2025 23:11
ifjob_retryisNone:
future=do_query()
else:
future=job_retry(do_query)()
Copy link
ContributorAuthor

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 inQueryJob, 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.

# 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.
orisinstance(exc,exceptions.NotFound)
Copy link
ContributorAuthor

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.

Copy link
ContributorAuthor

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

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

Need to play a similar trick as withget_job_retry, instead.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed in latest commit.

@tswast
Copy link
ContributorAuthor

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

get_job_retry=retry.with_predicate(
lambdaexc:isinstance(exc,core_exceptions.NotFound)
# Reference the original retry to avoid recursion.
orretry._predicate(exc)
Copy link
ContributorAuthor

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 thehttps://github.com/googleapis/python-api-core/blob/main/google/api_core/retry/retry_base.py code.

Copy link
ContributorAuthor

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Filedgoogleapis/python-api-core#796, in the meantime I'll pursue an alternative that doesn't require access to private attributes.

returnTrue

# Reference the original job_retry to avoid recursion.
returnjob_retry._predicate(exc)
Copy link
ContributorAuthor

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.

@tswast
Copy link
ContributorAuthor

tswast commentedFeb 19, 2025
edited
Loading

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 in8e20cb0. 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).

@tswast
Copy link
ContributorAuthor

@product-auto-labelproduct-auto-labelbot added size: lPull request size is large. and removed size: mPull request size is medium. labelsFeb 20, 2025
@tswast
Copy link
ContributorAuthor

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.

@tswast
Copy link
ContributorAuthor

tswast commentedFeb 21, 2025
edited
Loading

Coverage forretry.py should be fixed by189f559

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 thekokoro job, which includes thecover nox session, is passing on this commit (logs).

withpytest.raises(DataLoss,match="we lost your job, sorry"):
client.query("SELECT 1;",job_id=None)

deftest_query_job_rpc_fail_w_conflict_random_id_job_fetch_fails_no_retries(self):
Copy link
Contributor

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 thatQueryJob._begin() andclient.get_job() are called.

Copy link
Contributor

@LinchinLinchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you, lgtm.

@tswasttswastenabled auto-merge (squash)February 26, 2025 02:02
@tswasttswast merged commitc6d5f8a intomainFeb 26, 2025
15 of 23 checks passed
@tswasttswast deleted the issue2134-query404 branchFebruary 26, 2025 02:24
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@LinchinLinchinLinchin approved these changes

@Neenu1995Neenu1995Awaiting requested review from Neenu1995Neenu1995 was automatically assigned from googleapis/api-bigquery

Assignees

@chalmerlowechalmerlowe

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.size: lPull 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

3 participants

@tswast@Linchin@chalmerlowe

[8]ページ先頭

©2009-2025 Movatter.jp