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): say which roles fix a denied read (#99792)

Tom Owersbe611bee8ec6
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 7c35de9ce09c..004773a51d62 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
@@ -60,7 +60,14 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
- "PermissionDenied: 403 request failed": "BigQuery permission denied. Please check that your service account has the necessary permissions.",
+ # google-api-core raises `PermissionDenied` from the Storage Read API's
+ # `create_read_session`, whose message is the gRPC form "403 request failed: the user
+ # does not have '<permission>' permission for '<resource>'". Reading a table that way
+ # needs dataset read access and permission to open a read session on the project the
+ # read bills to, and the denial names only whichever one it hit first — so name both
+ # roles rather than leaving the customer to work out which grant is missing. Matched on
+ # the stable status wording, not the volatile permission and resource ids.
+ "PermissionDenied: 403 request failed": "BigQuery denied your service account access while reading your data. Grant it the BigQuery Data Viewer role on the dataset you're syncing and the Read Session User role on its project, then reconnect the source.",
# OAuth2 error code returned by Google's token endpoint when the service account grant
# is rejected — a rotated/revoked private key ("Invalid JWT Signature") or a deleted
# service account ("account not found"). Raised as a `RefreshError` while refreshing the
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 9e8e1940b89c..1d2ba443ee48 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
@@ -752,6 +752,26 @@ def test_non_retryable_errors_match_egress_denied_token_uri_endpoint(observed_er
assert all(non_retryable_errors[key] is not None for key in matching)
+ "observed_error",
+ [
+ # No permission to open a Storage Read API session on the project the read bills to.
+ "PermissionDenied: 403 request failed: the user does not have "
+ "'bigquery.readsessions.create' permission for 'projects/example-project'",
+ # Same gRPC wording, different missing permission and resource.
+ "PermissionDenied: 403 request failed: the user does not have "
+ "'bigquery.tables.getData' permission for table 'example-project:example_dataset.example_table'",
+ ],
+)
+def test_bigquery_storage_read_denial_is_non_retryable_with_guidance(observed_error):
+ """The Storage Read API denies access in gRPC wording rather than BigQuery's "Access Denied:"
+ prefix, so it has to match a key of its own or it retries forever with no guidance."""
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ matching = [key for key in non_retryable_errors if key in observed_error]
+ assert matching, "Storage Read API permission denial should be recognised as non-retryable"
+ assert all(non_retryable_errors[key] for key in matching)
+
+
@pytest.mark.parametrize(
"observed_error",
[