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): stop retrying a sync after its dataset is deleted (#80688)

Tom Owerse36de4cc49c5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
index 22fa47f6425c..8084968c3440 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
@@ -166,6 +166,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# carrying this exact wording (so the create/validate path shows it instead of the raw
# 404). Match it here too so the discovery activity treats it as non-retryable.
BIGQUERY_DATASET_NOT_FOUND_ERROR: BIGQUERY_DATASET_NOT_FOUND_ERROR,
+ # `bq_client.get_table(...)` in `_build_source_response` (see `bigquery.py`) issues a
+ # direct REST GET rather than a query job, so a dataset deleted or renamed after schema
+ # discovery surfaces as "GET .../tables/<table>?prettyPrint=false: Not found: Dataset
+ # <project>:<dataset>" — with no "was not found in location" suffix, since no query job
+ # (and therefore no queried-region mismatch) is involved. The "was not found in location"
+ # key above only covers the query-job path, so this slips through and retries forever.
+ # Retrying can't recover a deleted dataset; the user must restore or rename it back, or
+ # remove it from the sync. Matched on the stable "Not found: Dataset" wording rather than
+ # the volatile project/dataset id.
+ "Not found: Dataset": BIGQUERY_DATASET_NOT_FOUND_ERROR,
# A syntactically invalid project/dataset ID (e.g. a value carrying parentheses like
# "(default)") is rejected as a 400 "Invalid dataset ID ..." / "Invalid project ID ...".
# Schema discovery re-raises it as `BigQueryInvalidIdentifierError` carrying the friendly
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 d4c6d48f5382..9260a8fd9eb0 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
@@ -1830,6 +1830,27 @@ def test_bigquery_unsupported_region_is_non_retryable(location):
assert all(location not in key for key in matching), "match must not depend on the volatile location"
+def test_bigquery_dataset_not_found_during_sync_is_non_retryable():
+ """A dataset deleted/renamed after schema discovery surfaces from `get_table()` at sync time as a
+ google NotFound whose str() is "... Not found: Dataset <project>:<dataset>" — this REST GET path
+ carries no "was not found in location" suffix, unlike the query-job path covered by that pattern,
+ so it must be recognised as non-retryable via the "Not found: Dataset" pattern instead of retrying
+ a dataset that can't reappear within the run."""
+ error = NotFound(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/my-proj/datasets/my_dataset/"
+ "tables/my_table?prettyPrint=false: Not found: Dataset my-proj:my_dataset"
+ )
+
+ # Mirror the substring match in `update_external_data_job_model`.
+ error_msg = str(error)
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in error_msg]
+
+ assert matching, "a dataset-not-found 404 during sync should be recognised as non-retryable"
+ assert all(non_retryable_errors[key] is not None for key in matching)
+ assert "was not found in location" not in error_msg
+
+
def test_bigquery_table_not_found_during_sync_is_non_retryable():
"""A table deleted/renamed after schema discovery surfaces from `get_table()` at sync time as a
google NotFound whose str() is "... Not found: Table <project>:<dataset>.<table>" — distinct from