: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(bigquery): treat table-not-found at sync time as non-retryable (#65039)
Tom Owers9c5dda3bb64f
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex a58c14b4777a..a9b5cabcbc7f 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -96,6 +96,15 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# so match the stable phrasing here. Retrying can't recover — the user must fix the# dataset or set the correct region."was not found in location": "BigQuery couldn't find the configured dataset or table. It may have been deleted or renamed, or it may live in a different region — verify your dataset and table names, and set the dataset region in your source configuration if it isn't in the US.",+ # Raised from `bq_client.get_table(...)` in `_build_source_response` when the table being+ # synced no longer exists at sync time — it was deleted or renamed in BigQuery (common with+ # dbt-managed datasets) after schema discovery selected it. The google exception stringifies+ # as "... Not found: Table <project>:<dataset>.<table>", which the "was not found in+ # location" key (dataset-region 404s) doesn't cover, so it slips through and retries forever.+ # Retrying within the sync's window can't recover a missing table; the user must restore or+ # rename it back, or remove it from the sync. Matched on the stable "Not found: Table"+ # wording rather than the volatile table id.+ "Not found: Table": "BigQuery couldn't find a table this source is syncing — it was deleted or renamed after the source was set up. Restore or rename the table in BigQuery, or remove it from this source's synced tables, then re-enable the source.",# Raised by google-cloud-bigquery's `TableReference.from_string` when a table id has# more than the three `project.dataset.table` components. This happens when the# Dataset ID field is set to `project.dataset` instead of just `dataset` — we thendiff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex f64700edeb12..b4e6c635f084 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -854,6 +854,40 @@ def test_bigquery_dataset_not_found_in_location_is_non_retryable(location):assert any(pattern in error_msg for pattern in non_retryable_errors)+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+ the dataset-region "was not found in location" wording. It must be recognised as non-retryable via+ the "Not found: Table" pattern instead of retrying a table 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: Table my-proj:my_dataset.my_table"+ )++ # 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 table-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+++ "other_error",+ [+ # Transient server errors must stay retryable.+ "503 Service unavailable, please retry",+ "500 Internal error encountered, please retry",+ ],+)+def test_bigquery_table_not_found_key_does_not_match_unrelated_errors(other_error):+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ assert "Not found: Table" not in other_error+ assert not any(key in other_error for key in non_retryable_errors)++def test_bigquery_storage_read_client_disables_grpc_message_size_limit():"""Regression: the Storage Read API streams Arrow ReadRowsResponse messages that canexceed gRPC's default 4 MiB client receive limit (wide rows / large string columns like