Repository navigation
[Python] Reset BigQuery retries for each batch - #39995
Merged
claudevdm merged 5 commits intoOct 12, 2026
Merged
Conversation
bvolpato
marked this pull request as ready for review
October 11, 2026 03:30
Contributor
|
Assigning reviewers: R: @claudevdm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #39995 +/- ##
============================================
+ Coverage 56.16% 56.23% +0.06%
Complexity 2288 2288
============================================
Files 1124 1124
Lines 178336 178359 +23
Branches 1489 1489
============================================
+ Hits 100170 100293 +123
+ Misses 75645 75545 -100
Partials 2521 2521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 can send a recoverable row to
failed_rowsbecause an earlier successful batch consumed its retry allowance. The pipeline can finish successfully while that row is missing from BigQuery.The retry iterator currently belongs to the bundle and advances after every request, including successful requests. This also increases the backoff for later batches: after 20 successful batches, their first transient retry can sleep for 750 to 1500 seconds.
Create the iterator per flushed batch, matching the documented per-group retry limit. Failed rows and their insert IDs retain the existing retry behavior.
Reproduction with BigQuery
I ran a public
WriteToBigQuerypipeline against a temporary table in my own GCP project. After a successful realinsertAllrequest, the client injects one row-levelbackendErrorbefore sending the next request. This makes the transient failure reproducible without trying to induce a BigQuery outage.order-200order-100order-100,order-200order-100,order-200Every run finished
DONE. With the fix, the rejected batch retries using the same insert ID and the real request succeeds. Shuffle order can differ, so the injected error targets the second request rather than a specific order ID. The error is controlled; successful requests and table contents were verified against BigQuery.The reduced pipeline below uses an existing table with schema
run_mode:STRING,order_id:STRING,cents:INTEGER. Run it with the SDK being compared installed, GCP dependencies available, andgcloudauthenticated:Validation
Compared the complete BigQuery modules from current upstream and this PR over the same SDK dependency environment. The SDK selected Prism for the public pipeline. This comparison did not rebuild the entire SDK.
The focused regressions fail on upstream and pass with the fix. They cover successful prior batches, separate destinations, an earlier exhausted batch, and initial backoff. The zero-retry control passes on both implementations. The affected streaming transform, error-handling, and pipeline suites pass, as do repository-pinned YAPF, Ruff, and whitespace checks.
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'Credential discovery was stubbed only for the mocked local test suites. The live table reproduction used authenticated BigQuery requests.
Downsides
Each failing batch now receives its configured retry allowance independently. Several failing batches can therefore make more total attempts than the previous accidental bundle-wide limit. The configured per-batch limit is unchanged.
addresses #123orfixes #456).CHANGES.mdwith noteworthy changes.