Skip to content

: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.

fix(bigquery): give write-permission guidance for temp-table access denials (#67753)

Tom Owers5ce80c8e5213
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.py
index af2e8a29dc58..c645044a646b 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
@@ -58,6 +58,18 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# be repaired by retrying — the user must re-upload an intact JSON key file. Matched on the
# stable "Unable to load PEM file" wording rather than the volatile InvalidData detail.
"Unable to load PEM file": "We couldn't read the private key in your Google Cloud JSON key file — it appears truncated or corrupted. Please download a fresh service account key from Google Cloud and re-upload the JSON file.",
+ # Writing query results into the `__posthog_import_...` temp tables PostHog creates
+ # (`WRITE_TRUNCATE` in `_run_destination_query_with_job_retry`, on incremental / view /
+ # row-filtered reads) needs write access on the dataset those tables live in. When the
+ # service account only has read access, BigQuery rejects the copy with "Permission
+ # bigquery.tables.update denied on table <temp id>". This is a distinct problem from the
+ # read-side denials 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 fix a *write* failure. 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 (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.",
# 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
diff --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.py
index cd307cd20467..60c5d68e2d6b 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
@@ -831,6 +831,24 @@ 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)."
+ )
+ )
+ 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 friendly is not None
+ assert "write access" in friendly
+
+
@pytest.mark.parametrize(
"observed_error",
[