[Python] Reset BigQuery retries for each batch - #39995
Draft
bvolpato wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
BigQuery streaming inserts share one retry iterator across an entire bundle and advance it even for successful requests. With
max_retries=1, a successful batch exhausts the retry budget for the next batch: a transient failure then goes straight to the failed-row output. Prior successes also inflate the initial backoff for later batches; after 20 successful batches it reaches 750–1500 seconds.Create the retry iterator per batch, matching the documented per-group retry limit. Partial-failure retries still preserve the failed rows and their insert IDs. Tests cover consecutive batches, different destinations, a previously exhausted batch, initial backoff, and zero retries.
Testing
From
sdks/python, with the SDK and GCP test dependencies installed:python -m pytest apache_beam/io/gcp/bigquery_test.py -q \ -k 'successful_batches or exhausted_batch or zero_retries'All 5 new cases pass. Against the upstream implementation, 4 fail and the zero-retry compatibility case passes.
All 50 tests in the three affected streaming test classes also pass on Python 3.12. Credential discovery was stubbed only in the test process; the tests' existing request/client mocks remain in use:
The full module encountered an unrelated credential-lock failure in an existing read test, also reproduced on upstream. YAPF 0.43.0, Ruff 0.15.22, and
git diff --checkpass for the changed files.Downsides
The retry allowance now applies independently to each batch, so several failing batches can make more total attempts than the previous accidental shared limit. The configured per-batch limit remains unchanged.
CHANGES.mdwith the behavior change.