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 federated upstream "permission denied for table" as non-retryable (#64022)

Tom Owers71c1b8956d39
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.py
index f698add8e63d..778f6a651a3c 100644
--- a/posthog/temporal/data_imports/sources/bigquery/source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/source.py
@@ -59,6 +59,15 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# customer's service account — retrying can't resolve them; the user must grant the
# missing permission (or the referenced table/dataset must exist).
"Access Denied:": "BigQuery denied access to a table or dataset. Please ensure your service account has read access (the bigquery.tables.getData permission, e.g. the BigQuery Data Viewer role) on every dataset and table you're syncing, then reconnect the source.",
+ # Federated/external BigQuery tables (e.g. a Cloud SQL connection) read through to the
+ # underlying database. When that database's role lacks read access, BigQuery surfaces the
+ # upstream ACL failure inside a 400 BadRequest, e.g. "Error while reading data ...
+ # Failed to fetch row from PostgreSQL server. Error: ERROR: permission denied for table
+ # <name>". This is a deterministic permission problem on the customer's data source —
+ # retrying can't resolve it; the user must grant the federation's database user read
+ # access. The "Access Denied:"/403 keys above only cover BigQuery's own IAM wording, so
+ # this lowercase upstream form slips through and retries forever.
+ "permission denied for table": 'BigQuery couldn\'t read a federated table because the underlying database denied permission ("permission denied for table"). Please grant the database user behind your BigQuery connection read access to the table, then reconnect the source.',
# Raised from schema discovery (`get_columns`) and 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
diff --git a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
index f3506aa63c2c..48975864d0df 100644
--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -509,6 +509,25 @@ def test_non_retryable_errors_match_permission_denied(observed_error):
assert any(key in observed_error for key in non_retryable_errors)
+ "observed_error",
+ [
+ # Federated table backed by a Cloud SQL PostgreSQL server — BigQuery wraps the upstream
+ # ACL failure in a 400 BadRequest while reading query results.
+ str(
+ BadRequest(
+ "GET https://bigquery.googleapis.com/bigquery/v2/projects/p/queries/j?maxResults=0"
+ "&location=us-central1: Error while reading data, error message: Failed to fetch row "
+ "from PostgreSQL server. Error: ERROR: permission denied for table GroupParticipant"
+ )
+ ),
+ ],
+)
+def test_non_retryable_errors_match_federated_upstream_permission_denied(observed_error):
+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()
+ assert any(key in observed_error for key in non_retryable_errors)
+
+
@pytest.mark.parametrize(
"other_error",
[
@@ -516,6 +535,9 @@ def test_non_retryable_errors_match_permission_denied(observed_error):
"503 Service unavailable, please retry",
"500 Internal error encountered",
"Connection reset by peer",
+ # A federated-read failure that isn't a permission problem must stay retryable
+ "Error while reading data, error message: Failed to fetch row from PostgreSQL server. "
+ "Error: ERROR: connection to server timed out",
],
)
def test_non_retryable_errors_does_not_match_transient(other_error):