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): treat a deleted GCP project as non-retryable (#105861)

Tom Owers6ff19dfb80b1
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 d9dda7ea5625..92e09607fac9 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
@@ -278,6 +278,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# must fix the project reference. Matched on the stable guidance wording rather than the
# volatile project id that appears earlier in the message.
"Make sure it references valid GCP project": "BigQuery couldn't find the Google Cloud project this source references — it may have been deleted, or the Project ID in your service account key file (or the configured dataset project) may be incorrect. Verify the project exists in Google Cloud and correct the project details in your source configuration, then reconnect the source.",
+ # Raised as a 403 Forbidden by `bq_client.get_table(...)` in `_build_source_response` (and
+ # other direct REST calls) when the GCP project the source runs against has been deleted,
+ # e.g. "... Project #898288516447 has been deleted.". Unlike the "Make sure it references
+ # valid GCP project" key above (a 404 naming the friendly project id), this is a 403 naming
+ # the numeric project number, so it slips through and retries forever against a project that
+ # no longer exists. The `delete_table` cleanup path in `bigquery.py` already treats this
+ # wording as terminal (skips rather than raises); this key gives the same condition the same
+ # treatment on the main sync path. Matched on the stable "has been deleted" wording rather
+ # than the volatile project number.
+ "has been deleted": "BigQuery couldn't complete this sync because the Google Cloud project it uses has been deleted. Restore the project in Google Cloud, or update your source configuration to use a project that still exists, then reconnect 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 then
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 5fd5910161fe..3244b71e2ca1 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
@@ -1445,6 +1445,30 @@ def test_non_retryable_errors_match_permission_denied(observed_error):
assert any(key in observed_error for key in non_retryable_errors)
+ "observed_error",
+ [
+ # `bq_client.get_table(...)` in `_build_source_response` hitting a deleted GCP project.
+ str(
+ Forbidden(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/some-project/datasets/some_dataset/"
+ "tables/some_table?prettyPrint=false: Project #123456789 has been deleted."
+ )
+ ),
+ # Same condition surfacing from a different call site with a different HTTP verb/path.
+ str(Forbidden("POST https://bigquery.googleapis.com/bigquery/v2/jobs: Project #987654321 has been deleted.")),
+ ],
+)
+def test_non_retryable_errors_match_deleted_gcp_project(observed_error):
+ """A GCP project deleted after the source was set up can't be recovered by retrying — the
+ numeric project id (not the friendly one shown in the source config) means this is distinct
+ from the "Make sure it references valid GCP project" 404 key."""
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in observed_error]
+ assert matching, "Deleted GCP project error should be recognised as non-retryable"
+ assert all(non_retryable_errors[key] is not None for key in matching)
+
+
@pytest.mark.parametrize(
"observed_error,expected_key,expected_word",
[