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): treat readsessions.getData denial as non-retryable (#68006)

Tom Owersfbcdfd832a14
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 70cf3042ccec..f7798500affe 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
@@ -120,6 +120,16 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# 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 while reading rows from a Storage Read API stream (see `get_rows` in `bigquery.py`)
+ # when the service account can create a read session but lacks `bigquery.readsessions.getData`,
+ # the separate permission required to pull data from the session's streams. The
+ # google.api_core PermissionDenied stringifies as "there was an error operating on
+ # 'projects/<id>/.../streams/<id>': the user does not have 'bigquery.readsessions.getData'
+ # permission for '...'", so neither the "Access Denied:"/403 keys nor the readsessions.create
+ # key cover this wording, and it retries forever. Same IAM config fix as create — the BigQuery
+ # Read Session User role grants both. Matched on the stable permission name rather than the
+ # volatile session/stream ids.
+ "bigquery.readsessions.getData": "BigQuery denied access to the Storage Read API: your service account is missing the bigquery.readsessions.getData permission needed to read data from a read session. Please grant it (for example via the BigQuery Read Session User role) on the project you're syncing, then reconnect the source.",
# Raised from 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 google exception stringifies as "404 Not found: Dataset ... was
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 2895fc8379f8..bd4fefb3dd17 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
@@ -889,6 +889,18 @@ def test_bigquery_build_pipeline_trims_whitespace_in_destination_table():
"permission for 'projects/some-project'"
)
),
+ # Storage Read API stream-read denial — the session can be created but the account lacks
+ # `bigquery.readsessions.getData`. `str(PermissionDenied)` is "there was an error operating
+ # on '.../streams/...': the user does not have 'bigquery.readsessions.getData' permission for
+ # '...'", which neither the "Access Denied:" / "403 request failed" nor the readsessions.create
+ # keys cover.
+ str(
+ PermissionDenied(
+ "there was an error operating on 'projects/some-project/locations/us/sessions/sess/"
+ "streams/strm': the user does not have 'bigquery.readsessions.getData' permission for "
+ "'projects/some-project/locations/us/sessions/sess/streams/strm'"
+ )
+ ),
],
)
def test_non_retryable_errors_match_permission_denied(observed_error):