: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 dataset-not-found-in-location as non-retryable (#63763)
Tom Owersb4a345953146
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex 5771f3a396b6..f698add8e63d 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -42,7 +42,6 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):def get_non_retryable_errors(self) -> dict[str, str | None]:return {"PermissionDenied: 403 request failed": "BigQuery permission denied. Please check that your service account has the necessary permissions.",- "NotFound: 404": "BigQuery dataset or table not found. Please verify your project, dataset, and table names.",# OAuth2 error code returned by Google's token endpoint when the service account grant# is rejected — a rotated/revoked private key ("Invalid JWT Signature") or a deleted# service account ("account not found"). Raised as a `RefreshError` while refreshing the@@ -60,6 +59,13 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# customer's service account — retrying can't resolve them; the user must grant the# missing permission (or the referenced table/dataset must exist)."Access Denied:": "BigQuery denied access to a table or dataset. Please ensure your service account has read access (the bigquery.tables.getData permission, e.g. the BigQuery Data Viewer role) on every dataset and table you're syncing, then reconnect the source.",+ # Raised from schema discovery (`get_columns`) and query jobs when the configured+ # dataset/table doesn't exist in the location we query — the dataset was deleted or+ # renamed, or it lives in a different region than the one we run against. The google+ # exception stringifies as "404 Not found: Dataset ... was not found in location US",+ # 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 the shared `evolve_pyarrow_schema` in `pipelines/pipeline/utils.py`# when an integer column's source type was widened (e.g. `INT64` widened from a# narrower numeric type) after the destination table was created with the narrowerdiff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex 29f88b363a01..f3506aa63c2c 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -573,3 +573,24 @@ def test_has_duplicate_primary_keys_captures_unexpected_errors():assert result is Falsemock_capture.assert_called_once()+++ "location",+ ["US", "EU", "asia-northeast1"],+)+def test_bigquery_dataset_not_found_in_location_is_non_retryable(location):+ """A deleted/renamed dataset (or one in a region we don't query) surfaces from schema+ discovery as a google-api-core NotFound. Its str() is "404 Not found: Dataset ... was+ not found in location <X>", which must be recognised as non-retryable via the+ "was not found in location" pattern instead of retrying forever."""+ error = NotFound(+ f"Not found: Dataset my-proj:my_dataset was not found in location {location}; "+ f"reason: notFound, message: Not found: Dataset my-proj:my_dataset was not found in location {location}"+ )++ # Mirror the substring match in `sync_new_schemas_activity` / `update_external_data_job_model`.+ error_msg = str(error)+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()++ assert any(pattern in error_msg for pattern in non_retryable_errors)