: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): treat unparseable private key as non-retryable (#65082)
Tom Owersb4a3e077d8ce
diff --git a/posthog/temporal/data_imports/sources/bigquery/source.py b/posthog/temporal/data_imports/sources/bigquery/source.pyindex a9b5cabcbc7f..62319b2731d9 100644--- a/posthog/temporal/data_imports/sources/bigquery/source.py+++ b/posthog/temporal/data_imports/sources/bigquery/source.py@@ -50,6 +50,13 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):# stable `invalid_grant` code rather than `RefreshError`, which can also wrap transient# token-endpoint failures that should stay retryable."invalid_grant": "Your BigQuery service account credentials were rejected by Google. The key may have been rotated or revoked, or the service account deleted. Please upload a new Google Cloud JSON key file.",+ # Raised from `bigquery_client` when `service_account.Credentials.from_service_account_info`+ # parses the uploaded key file's `private_key`. A truncated or corrupted PEM body (wrong+ # padding, stray characters, copy-paste damage) makes the `cryptography` backend reject it+ # as a `ValueError: Unable to load PEM file. ... InvalidData(InvalidPadding)`. The key can't+ # 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.",# 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/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.pyindex b4e6c635f084..2ebb85bb6c46 100644--- a/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py+++ b/posthog/temporal/data_imports/sources/bigquery/tests/test_source.py@@ -459,6 +459,21 @@ def test_non_retryable_errors_match_offline_token_uri_endpoint(observed_error):assert all(non_retryable_errors[key] is not None for key in matching)+ "observed_error",+ [+ # Corrupted/truncated private key body in the uploaded service account JSON.+ "Unable to load PEM file. See https://cryptography.io/en/latest/faq/#why-can-t-i-import-my-pem-file for more details. InvalidData(InvalidPadding)",+ "ValueError: Unable to load PEM file. InvalidData(InvalidByte(1, 45))",+ ],+)+def test_bigquery_unparseable_private_key_is_non_retryable(observed_error):+ non_retryable_errors = BigQuerySource().get_non_retryable_errors()+ matching = [key for key in non_retryable_errors if key in observed_error]+ assert matching, "Unparseable private key error should be recognised as non-retryable"+ assert all(non_retryable_errors[key] is not None for key in matching)++@pytest.mark.parametrize("transient_error",[