: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): surface job-creation permission guidance as non-retryable (#68008)
Tom Owers4b8972a5af9b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.pyindex 0b45d0677ec1..2ed8c6b438de 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py@@ -81,6 +81,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# config problem — retrying can't grant the permission. Matched on the stable permission name,# not the volatile dataset id."bigquery.tables.create": "BigQuery denied permission to create a temporary table PostHog needs in your dataset. PostHog copies query results into temporary tables before reading them, so read access alone isn't enough. Please grant your service account permission to create tables (for example the BigQuery Data Editor role) on the dataset where these temporary tables are created — your main dataset, or the temporary dataset if you configured one — then reconnect the source.",+ # BigQuery rejects query-job creation (POST .../jobs) with "Access Denied: Project <id>:+ # User does not have bigquery.jobs.create permission in project <id>." when the service+ # account can read the data but can't run query jobs in the project the jobs bill to. We+ # create query jobs throughout the sync (primary-key discovery, row counts, temp-table+ # copies), so this fails before any rows are read. Like the tables.update key above, the+ # generic "Access Denied:" key would match first and misdirect the customer to grant+ # *read* access (Data Viewer), which can't grant job creation — so keep this key above it.+ # Deterministic IAM config problem; retrying can't grant the permission. Matched on the+ # stable permission name, not the volatile project id.+ "bigquery.jobs.create": "BigQuery denied your service account permission to run query jobs — it's missing the bigquery.jobs.create permission on the project it queries. Read access alone isn't enough, because PostHog runs query jobs to sync your data. Please grant your service account permission to run jobs (for example the BigQuery Job User role) on that project, then reconnect the source.",# 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'sdiff --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 5685ece46109..de27164c51ff 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@@ -947,6 +947,24 @@ def test_temp_table_write_denial_surfaces_write_permission_guidance(observed_errassert expected_word in friendly+def test_job_create_denial_surfaces_job_permission_guidance():+ # A bigquery.jobs.create denial also contains "Access Denied:", so both keys match.+ # external_data_job surfaces the first matching key's message, so the job-creation key must sit+ # above "Access Denied:" — otherwise the customer is told to grant read access to fix a failure+ # that read access can't resolve.+ observed_error = str(+ Forbidden(+ "POST https://bigquery.googleapis.com/bigquery/v2/projects/p/jobs?prettyPrint=false: "+ "Access Denied: Project p: User does not have bigquery.jobs.create permission in project p."+ )+ )+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ first_key, friendly = next((key, msg) for key, msg in non_retryable_errors.items() if key in observed_error)+ assert first_key == "bigquery.jobs.create"+ assert friendly is not None+ assert "run query jobs" in friendly++@pytest.mark.parametrize("observed_error",[