: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 write-access guidance for tables.create denial (#68010)
Tom Owers31b22ec60304
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 15807e52765f..70cf3042ccec 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@@ -71,6 +71,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# Matched on the stable permission name (also covers `bigquery.tables.updateData`), not# the volatile temp-table id."bigquery.tables.update": "BigQuery denied write access to a temporary table PostHog creates 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 write access (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.",+ # Before it can write into the `__posthog_import_...` temp tables, `_run_destination_query_with_job_retry`+ # (WRITE_TRUNCATE, on incremental / view / row-filtered reads) needs to *create* them in the+ # dataset they live in. A service account with only read access is denied with "Permission+ # bigquery.tables.create denied on dataset <id>". Like `bigquery.tables.update` this is a+ # write-side denial, distinct from the read-side ones the "Access Denied:" key below covers —+ # and that key would match this message first and misdirect the customer to grant *read* access+ # (Data Viewer), which can't create a table. Keep this key above "Access Denied:" so the+ # write-specific guidance wins. Deterministic IAM 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 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 write access (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 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 9e0304a1a647..2895fc8379f8 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@@ -896,20 +896,38 @@ def test_non_retryable_errors_match_permission_denied(observed_error):assert any(key in observed_error for key in non_retryable_errors)-def test_temp_table_write_denial_surfaces_write_permission_guidance():- # A tables.update denial on a PostHog temp table also contains "Access Denied:", so both keys- # match. external_data_job surfaces the first matching key's message, so the write-specific key- # must sit above "Access Denied:" — otherwise the customer is told to grant read access to fix a- # write failure.- observed_error = str(- Forbidden(- "Access Denied: Table prj:ds.__posthog_import_abc_123: Permission bigquery.tables.update "- "denied on table prj:ds.__posthog_import_abc_123 (or it may not exist)."- )- )+ "observed_error,expected_key",+ [+ # Writing into a PostHog temp table needs bigquery.tables.update...+ (+ str(+ Forbidden(+ "Access Denied: Table prj:ds.__posthog_import_abc_123: Permission bigquery.tables.update "+ "denied on table prj:ds.__posthog_import_abc_123 (or it may not exist)."+ )+ ),+ "bigquery.tables.update",+ ),+ # ...and creating it needs bigquery.tables.create.+ (+ str(+ Forbidden(+ "Access Denied: Dataset prj:ds: Permission bigquery.tables.create denied on dataset "+ "prj:ds (or it may not exist)."+ )+ ),+ "bigquery.tables.create",+ ),+ ],+)+def test_temp_table_write_denial_surfaces_write_permission_guidance(observed_error, expected_key):+ # These denials also contain "Access Denied:", so both keys match. external_data_job surfaces the+ # first matching key's message, so each write-specific key must sit above "Access Denied:" —+ # otherwise the customer is told to grant read access to fix a write failure.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.tables.update"+ assert first_key == expected_keyassert friendly is not Noneassert "write access" in friendly