: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): skip duplicate-key probe noise on broken view definitions (#73655)
Tom Owersa0be88515a18
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.pyindex 05ca38fb3e62..e84de7002fb6 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@@ -715,6 +715,18 @@ def _is_bigquery_resource_exceeded(error: BadRequest) -> bool:return "resourcesExceeded" in reasons or BIGQUERY_RESOURCES_EXCEEDED_ERROR in str(error)+def _is_bigquery_view_parse_failure(error: BadRequest) -> bool:+ """True for BigQuery's `failed to parse view` query failures.++ BigQuery raises this when the table being probed is itself a view whose definition no+ longer compiles (a column, UDF, or upstream table it references was renamed or dropped).+ See the `"failed to parse view"` key in `BigQuerySource.get_non_retryable_errors` for the+ main read path — that's a customer-side view problem we can't fix, so this best-effort+ probe should degrade gracefully instead of treating it as an actionable crash.+ """+ return "failed to parse view" in str(error)++def _has_duplicate_primary_keys(table: bigquery.Table, client: bigquery.Client, primary_keys: list[str] | None) -> bool:if not primary_keys or len(primary_keys) == 0:return False@@ -745,6 +757,17 @@ def _has_duplicate_primary_keys(table: bigquery.Table, client: bigquery.Client,table.table_id,)return False+ if _is_bigquery_view_parse_failure(e):+ # The table being probed is itself a broken view — its own definition doesn't+ # compile, so BigQuery rejects the probe before it can even run. That's a+ # customer-side view problem this check can't fix, and this check is best-effort,+ # so skip it quietly rather than capturing non-actionable noise on every sync.+ structlog.get_logger().warning(+ "Skipping duplicate primary key check for BigQuery table %s.%s: view failed to parse",+ table.dataset_id,+ table.table_id,+ )+ return Falsecapture_exception(e)except Exception as e:capture_exception(e)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.pyindex d41167b8c6f1..bc294f29ba9c 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@@ -1368,6 +1368,27 @@ def test_has_duplicate_primary_keys_skips_resource_exceeded_quietly(exception):mock_capture.assert_not_called()+ "exception",+ [+ BadRequest(+ "Name is_qualified not found inside visit; failed to parse view 'my_dataset.my_view' at [5:19]; "+ "reason: invalidQuery, location: query, message: Name is_qualified not found inside visit; "+ "failed to parse view 'my_dataset.my_view' at [5:19]"+ ),+ BadRequest("Invalid table-valued function EXTERNAL_QUERY; failed to parse view 'my_dataset.my_view' at [1:1]"),+ ],+)+def test_has_duplicate_primary_keys_skips_view_parse_failure_quietly(exception):+ """A `failed to parse view` BigQuery error during the best-effort duplicate-key probe must NOT+ be captured to error tracking — the probed table is itself a broken view, a customer-side+ problem that otherwise fires on every sync of that table."""+ result, mock_capture = _run_has_duplicate_primary_keys(exception)++ assert result is False+ mock_capture.assert_not_called()++def test_has_duplicate_primary_keys_captures_unexpected_bad_request():"""A non-resource BadRequest (e.g. a genuinely malformed probe query) is still captured so wedon't lose visibility into real bugs."""