Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(bigquery): retry a second jobInternalError wording (#80795)

Tom Owers14bf49dd97f1
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
index ba2dcf0a6d05..e6e171d1de31 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/bigquery.py
@@ -195,6 +195,13 @@ BIGQUERY_VALIDATION_GENERIC_ERROR = (
# the job in place — matched on its stable retry-recommendation wording, not the volatile job id/URL.
_BIGQUERY_JOB_RETRY_RECOMMENDED = "Retrying the job may solve the problem"
+# BigQuery has a second wording for the same transient `jobInternalError` condition above, seen from
+# the same `jobs.getQueryResults` call: "The job encountered an internal error during execution and
+# was unable to complete successfully." — no "Retrying the job may solve the problem" suffix, so
+# `_BIGQUERY_JOB_RETRY_RECOMMENDED` doesn't catch it and it escapes `QueryJob.result()` the same way.
+# Matched on its own stable wording, not the volatile job id/URL.
+_BIGQUERY_JOB_INTERNAL_ERROR = "encountered an internal error during execution and was unable to complete successfully"
+
def _is_transient_rate_quota_exceeded(exc: Exception) -> bool:
"""True for BigQuery's per-second rate quotas, which are transient and recover on their own.
@@ -236,8 +243,10 @@ def _query_should_retry(exc: Exception) -> bool:
# Defer to the library's own default predicate for the reasons it already covers; importing it
# directly (rather than reading the private `Retry._predicate`) means a library rename fails
# loudly at import instead of silently dropping that default coverage.
+ message = str(exc)
return (
- _BIGQUERY_JOB_RETRY_RECOMMENDED in str(exc)
+ _BIGQUERY_JOB_RETRY_RECOMMENDED in message
+ or _BIGQUERY_JOB_INTERNAL_ERROR in message
or _is_transient_rate_quota_exceeded(exc)
or _is_transient_queued_jobs_quota_exceeded(exc)
or _job_should_retry(exc)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
index 2ad248fe5486..d4c6d48f5382 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -1518,6 +1518,13 @@ def test_has_duplicate_primary_keys_captures_unexpected_errors():
"?maxResults=0&location=US&prettyPrint=false: The job encountered an error during execution. "
"Retrying the job may solve the problem."
),
+ # A second wording for the same transient `jobInternalError` condition, with no
+ # retry-recommendation suffix (volatile project/job id redacted).
+ BadRequest(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/<redacted>/queries/<redacted>"
+ "?maxResults=0&location=US&prettyPrint=false: The job encountered an internal error during "
+ "execution and was unable to complete successfully."
+ ),
# The library default's own retryable reasons must still be honoured.
BadRequest("query failed", errors=[{"reason": "backendError", "message": "internal error"}]),
BadRequest("query failed", errors=[{"reason": "rateLimitExceeded", "message": "slow down"}]),