: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 missing Storage Read API permission as non-retryable (#64220)
Tom Owers19cd3bbad95e
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex acb79cbeea54..9d845f418643 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -68,6 +68,16 @@ 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.',+ # 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 as+ # "403 request failed: the user does not have 'bigquery.readsessions.create' permission+ # for 'projects/<id>'", so neither the "Access Denied:"/403 keys nor "PermissionDenied:+ # 403 request failed" cover this wording, and it retries forever. This is an IAM config+ # problem on the customer's service account — retrying can't resolve it; the user must+ # grant the missing permission (e.g. the BigQuery Read Session User role). Matched on the+ # stable permission name rather than the volatile project id.+ "bigquery.readsessions.create": "BigQuery denied access to the Storage Read API: your service account is missing the bigquery.readsessions.create permission. Please grant it (for example via the BigQuery Read Session User role) on the project you're syncing, then reconnect the source.",# Raised from schema discovery (`get_columns`) and query jobs when the configured# dataset/table doesn't exist in the location we query — the dataset was deleted or# renamed, or it lives in a different region than the one we run against. The googlediff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex 892997ce79ac..2ba6d10578ba 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -526,6 +526,15 @@ def test_bigquery_build_pipeline_trims_whitespace_in_destination_table():),# Permission to list tables in a dataset is also denied with the same prefixstr(Forbidden("Access Denied: Permission bigquery.tables.list denied on dataset prj:ds.")),+ # Storage Read API `create_read_session` denial — `str(PermissionDenied)` is "403 request+ # failed: the user does not have 'bigquery.readsessions.create' permission for 'projects/...'",+ # which the "Access Denied:" / "PermissionDenied: 403 request failed" keys don't cover.+ str(+ PermissionDenied(+ "request failed: the user does not have 'bigquery.readsessions.create' "+ "permission for 'projects/some-project'"+ )+ ),],)def test_non_retryable_errors_match_permission_denied(observed_error):