Repository navigation
fix: Retry BigQuery entity table expiration on stale etag - #7239
Open
luisSilva1234 wants to merge 1 commit into
Open
luisSilva1234 wants to merge 1 commit into
luisSilva1234 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🔍 Devin Review: 5 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
luisSilva1234
force-pushed
the
fix/bigquery-entity-table-expiration-race
branch
from
November 25, 2026 11:52
6a982a2 to
2e14ad2
Compare
The BigQuery offline store sets a 30-minute expiration on the temporary entity table it uploads by calling client.get_table() followed by client.update_table(table, ["expires"]). update_table sends a conditional PATCH keyed on the etag returned by get_table(). Shortly after the job that creates the table completes, BigQuery can still be asynchronously finalizing the table's metadata (e.g. row counts, last modified time), which changes its etag server-side. If that happens between get_table() and update_table(), the PATCH is rejected with a PreconditionFailed (412, "did not meet condition IF_MATCH"), even though the upload itself succeeded. Because this is a table metadata PATCH rather than a BigQuery job, the failure leaves no trace in the BigQuery Jobs Explorer, making it look spurious and hard to diagnose from the GCP console. Extract the expiration logic into _set_table_expiration() and retry it on PreconditionFailed, refetching the table for a fresh etag before each retry. Signed-off-by: Luis Silva <58522514+luisSilva1234@users.noreply.github.com>
luisSilva1234
force-pushed
the
fix/bigquery-entity-table-expiration-race
branch
from
November 25, 2026 12:01
2e14ad2 to
8bcb5aa
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7239 +/- ##
=======================================
Coverage 54.10% 54.11%
=======================================
Files 467 467
Lines 58940 58945 +5
Branches 8688 8688
=======================================
+ Hits 31890 31897 +7
+ Misses 24892 24890 -2
Partials 2158 2158
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
What this PR does / why we need it:
The BigQuery offline store sets a 30-minute expiration on the temporary entity table it uploads via
client.get_table()followed byclient.update_table(table, ["expires"]).update_tablesends a conditional PATCH keyed on the ETag fromget_table().Shortly after the upload job completes, BigQuery can still be asynchronously finalizing the table's metadata, which changes its ETag server-side. If that happens between the two calls, the PATCH is rejected with
PreconditionFailed(412, "did not meet condition IF_MATCH") — even though the upload itself succeeded. Since this is a metadata PATCH and not a BigQuery job, the failure is invisible in the Jobs Explorer, making it confusing to diagnose.Note: this is BigQuery's ETag-based optimistic concurrency control working as designed (see
Client.update_table's own docstring: a staletable.etagcauses the write to be rejected unless the server-side ETag still matches). The twist is that the ETag is being changed by BigQuery's own asynchronous metadata finalization, not a genuine concurrent modification from another client, so there's no real conflict to resolve — refetch-and-retry is the correct remedy.This PR extracts the expiration logic into
_set_table_expiration()and retries it (up to 5 attempts) onPreconditionFailed, refetching the table for a fresh ETag before each retry.Which issue(s) this PR fixes:
Fixes #7238
Checks
git commit -s)Testing Strategy
Misc
Added
TestSetTableExpirationcovering: success on first attempt, recovery after a transientPreconditionFailed, and exhausting retries. Verified withblack --checkandruff checkon the changed files.