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): skip temp-table cleanup delete after a project deletion (#105111)

Tom Owers2b93429bdd90
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 ba594dea3fec..b11c28adbfc5 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
@@ -1667,6 +1667,16 @@ class BigQueryImplementation(SQLSourceImplementation[BigQuerySourceConfig, bigqu
if "invalid_grant" in str(e):
raise
inputs.logger.warning(f"Skipping cleanup of bigquery destination table {destination_table}: {e}")
+ except Forbidden as e:
+ # BigQuery rejects the delete with a 403 reading "Project #<id> has been deleted."
+ # when the customer's whole GCP project was removed after the sync started. Unlike
+ # the genuine permission denial the comment above guards against, there's no
+ # readable copy left to protect here — the project, dataset, and table are all
+ # already gone — so retrying only repeats the identical failure forever. Matched on
+ # the stable wording, not the volatile project number.
+ if "has been deleted" not in str(e):
+ raise
+ inputs.logger.warning(f"Skipping cleanup of bigquery destination table {destination_table}: {e}")
def _build_source_response(
self,
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 c6696245bdd4..d8fc1103dc47 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
@@ -355,10 +355,23 @@ def test_bigquery_build_pipeline_resolves_dataset_routing(
assert mock_delete.call_args.kwargs["table_id"] == expected_table_id
-def test_bigquery_build_pipeline_swallows_transient_cleanup_refresh_error():
- """A transient token-refresh failure (e.g. a 502 from Google's OAuth endpoint) while deleting
- the run's own destination table must not turn an otherwise-successful sync into a failure —
- retrying the whole sync just to retry this delete is wasteful."""
+ "exception",
+ [
+ # A transient token-refresh failure (e.g. a 502 from Google's OAuth endpoint).
+ RefreshError("<!DOCTYPE html><html><head><title>Error 502 (Server Error)</title></head></html>"),
+ # The customer's whole GCP project was deleted after the sync started — there's no
+ # readable copy left to protect, unlike a live-project "Access Denied:" permission denial.
+ Forbidden(
+ "DELETE https://bigquery.googleapis.com/bigquery/v2/projects/proj/datasets/ds/tables/tbl"
+ "?prettyPrint=false: Project #123456789 has been deleted."
+ ),
+ ],
+)
+def test_bigquery_build_pipeline_swallows_transient_cleanup_errors(exception):
+ """A transient failure while deleting the run's own destination table must not turn an
+ otherwise-successful sync into a failure — retrying the whole sync just to retry this delete
+ is wasteful."""
config = _make_config()
logger = mock.MagicMock()
inputs = _make_inputs(logger=logger)
@@ -371,9 +384,7 @@ def test_bigquery_build_pipeline_swallows_transient_cleanup_refresh_error():
mock.patch.object(BigQueryImplementation, "_build_source_response", return_value=build_result),
mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.bigquery.bigquery.delete_table",
- side_effect=RefreshError(
- "<!DOCTYPE html><html><head><title>Error 502 (Server Error)</title></head></html>"
- ),
+ side_effect=exception,
),
):
result = BigQuerySource().source_for_pipeline(config, inputs)