: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 BigQuery "Access Denied" as non-retryable (#63776)
Tom Owers7f5118601f79
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex f8ef13afda57..5771f3a396b6 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -51,6 +51,15 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# stable `invalid_grant` code rather than `RefreshError`, which can also wrap transient# token-endpoint failures that should stay retryable."invalid_grant": "Your BigQuery service account credentials were rejected by Google. The key may have been rotated or revoked, or the service account deleted. Please upload a new Google Cloud JSON key file.",+ # BigQuery prefixes every IAM/permission failure with "Access Denied:" — e.g.+ # "Access Denied: Table <id>: Permission bigquery.tables.getData denied on table <id>+ # (or it may not exist).". The matched string above only covers the REST client's+ # "PermissionDenied: 403 request failed" wording; the Storage Read API raises a+ # google.api_core PermissionDenied whose `str()` is "403 Access Denied: ..." instead,+ # so it slips through and retries forever. These are config/permission problems on the+ # 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 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 3888dec58945..3b4310500343 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -3,7 +3,7 @@ from freezegun import freeze_timefrom unittest import mockfrom dateutil import parser-from google.api_core.exceptions import Forbidden, NotFound+from google.api_core.exceptions import Forbidden, NotFound, PermissionDeniedfrom posthog.temporal.data_imports.pipelines.pipeline.typings import SourceInputsfrom posthog.temporal.data_imports.sources.bigquery.bigquery import (@@ -485,3 +485,36 @@ def test_bigquery_build_pipeline_trims_whitespace_in_destination_table():assert mock_delete_all.call_args.kwargs["project_id"] == "524098457564"assert mock_delete_all.call_args.kwargs["dataset_id"] == "bigquery_aloalo"assert mock_delete.call_args.kwargs["table_id"] == expected_table_id+++ "observed_error",+ [+ # Storage Read API permission failure — `str(PermissionDenied)` is "403 Access Denied: ..."+ str(+ PermissionDenied(+ "Access Denied: Table prj:ds.fct__conversions: Permission bigquery.tables.getData "+ "denied on table prj:ds.fct__conversions (or it may not exist)."+ )+ ),+ # Permission to list tables in a dataset is also denied with the same prefix+ str(Forbidden("Access Denied: Permission bigquery.tables.list denied on dataset prj:ds.")),+ ],+)+def test_non_retryable_errors_match_permission_denied(observed_error):+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ assert any(key in observed_error for key in non_retryable_errors)+++ "other_error",+ [+ # Transient server / connection errors must stay retryable+ "503 Service unavailable, please retry",+ "500 Internal error encountered",+ "Connection reset by peer",+ ],+)+def test_non_retryable_errors_does_not_match_transient(other_error):+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ assert not any(key in other_error for key in non_retryable_errors)