: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 create-permission guidance for temp-table denials (#68009)
Tom Owersfcb912e454c6
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 f7798500affe..0b45d0677ec1 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,16 +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.",+ # Creating the `__posthog_import_...` temp tables (the `WRITE_TRUNCATE` destination in+ # `_run_destination_query_with_job_retry`, on incremental / view / row-filtered reads) needs+ # create access on the dataset those tables live in. When the service account only has read+ # access, BigQuery rejects it with "Permission bigquery.tables.create denied on dataset+ # <id>" — the create-side twin of the `bigquery.tables.update` denial above. Like that key,+ # it also starts with "Access Denied:", so it must sit above that key or the customer is told+ # to grant *read* access (Data Viewer), which can't fix a *create* failure. 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 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 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 bd4fefb3dd17..5685ece46109 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@@ -909,9 +909,9 @@ def test_non_retryable_errors_match_permission_denied(observed_error):@pytest.mark.parametrize(- "observed_error,expected_key",+ "observed_error,expected_key,expected_word",[- # Writing into a PostHog temp table needs bigquery.tables.update...+ # Overwriting a PostHog temp table — denied with bigquery.tables.update on the table.(str(Forbidden(@@ -920,8 +920,9 @@ def test_non_retryable_errors_match_permission_denied(observed_error):)),"bigquery.tables.update",+ "write access",),- # ...and creating it needs bigquery.tables.create.+ # Creating a PostHog temp table — denied with bigquery.tables.create on the dataset.(str(Forbidden(@@ -930,18 +931,20 @@ def test_non_retryable_errors_match_permission_denied(observed_error):)),"bigquery.tables.create",+ "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.+def test_temp_table_write_denial_surfaces_write_permission_guidance(observed_error, expected_key, expected_word):+ # A temp-table write/create denial also contains "Access Denied:", so both that generic key and the+ # write-specific key 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/create 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 == expected_keyassert friendly is not None- assert "write access" in friendly+ assert expected_word in friendly@pytest.mark.parametrize(