: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 unparseable import views as non-retryable (#64615)
Tom Owersfccaf282ecfb
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex 4a3615140f38..662fde389b57 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -68,6 +68,17 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# access. The "Access Denied:"/403 keys above only cover BigQuery's own IAM wording, so# this lowercase upstream form slips through and retries forever."permission denied for table": 'BigQuery couldn\'t read a federated table because the underlying database denied permission ("permission denied for table"). Please grant the database user behind your BigQuery connection read access to the table, then reconnect the source.',+ # BigQuery raises this 400 BadRequest when it can't compile a view it's importing, e.g.+ # "Invalid table-valued function EXTERNAL_QUERY; failed to parse view '<dataset>.<view>'".+ # For a federated EXTERNAL_QUERY view this means the upstream schema drifted away from the+ # view definition — a column the view selects was renamed or dropped in the source database+ # ("prepare statement failed. Error: ERROR: column \"x\" does not exist"). It's a+ # deterministic mismatch between the customer's view and their data; retrying can't recover+ # it — they must fix the view definition or restore the column. The "permission denied for+ # table" / "Access Denied:" keys only cover federation ACL failures, so this slips through+ # and retries forever. Matched on BigQuery's stable "failed to parse view" wording rather+ # than the volatile view/column names.+ "failed to parse view": "BigQuery couldn't read a view it was importing because its definition no longer matches the underlying data — a column it references was renamed or removed (for federated query views, in the upstream database). Please update the view definition (or restore the column), then reconnect the source.",# Raised from the Storage Read API's `create_read_session` (see `get_rows` in# `bigquery.py`) when the service account is missing the `bigquery.readsessions.create`# permission the Read API requires. The google.api_core PermissionDenied stringifies asdiff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex 1ad04d499729..9a3cb472c110 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -655,6 +655,28 @@ def test_non_retryable_errors_match_federated_upstream_permission_denied(observeassert any(key in observed_error for key in non_retryable_errors)+ "observed_error",+ [+ # Federated EXTERNAL_QUERY view whose upstream schema drifted — a column the view selects was+ # renamed/dropped in the source database, so BigQuery can't compile the view.+ str(+ BadRequest(+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/p/queries/j?maxResults=0"+ "&location=us-central1: Invalid table-valued function EXTERNAL_QUERY; failed to parse "+ "view 'analytics.SurveyResponse'\nFailed to get query schema from PostgreSQL server, "+ 'prepare statement failed. Error: ERROR: column "participantId" does not exist'+ )+ ),+ ],+)+def test_non_retryable_errors_match_unparseable_view(observed_error):+ """A view whose definition no longer matches the underlying data (e.g. a federated query+ references a dropped column) can't be recovered by retrying — the user must fix the view."""+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ assert any(key in observed_error for key in non_retryable_errors)++@pytest.mark.parametrize("observed_error",[