: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(google_analytics): stop retrying invalid runReport requests (#107971)
Tom Owers1b2b59a44b5d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.pyindex 30bf46f3ae14..cbcc67c873cb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py@@ -72,6 +72,16 @@ class GoogleAnalyticsSource(ResumableSource[GoogleAnalyticsSourceConfig, GoogleAdef get_non_retryable_errors(self) -> dict[str, str | None]:return {+ # `_run_report` raises this verbatim for any runReport response that isn't quota+ # exhaustion or a 5xx — GA4 rejected the request itself (e.g. an invalid custom+ # report dimension/metric name, or an incompatible dimension/metric combination),+ # so retrying replays the identical request and fails identically every time.+ "400 Client Error: Bad Request for url: https://analyticsdata.googleapis.com": (+ "Google Analytics rejected this report request as invalid. This is usually caused by "+ "a custom report dimension or metric name — GA4 API names are camelCase (e.g. "+ "'bounceRate', not 'bounce_rate'). Check your custom report configuration against the "+ "GA4 Data API schema, then try again."+ ),"401 Client Error": "Your Google Analytics connection is invalid or expired. Please reconnect your account.","403 Client Error": "PostHog is not authorized to read this Google Analytics property. Please make sure the connected Google account has access to the property.","ACCESS_TOKEN_SCOPE_INSUFFICIENT": "Insufficient permissions. Please reconnect your Google Analytics account with the required scopes.",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.pyindex 4a396c9dfbc9..317674a5181d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py@@ -306,6 +306,22 @@ def test_non_retryable_errors_matches_revoked_refresh_token():assert error_message_matches(observed_error, non_retryable_errors)+ "error_msg",+ [+ "400 Client Error: Bad Request for url: https://analyticsdata.googleapis.com/v1beta/properties/123456789:runReport",+ "401 Client Error: Unauthorized for url: https://analyticsdata.googleapis.com/v1beta/properties/123456789:runReport",+ "403 Client Error: Forbidden for url: https://analyticsdata.googleapis.com/v1beta/properties/123456789:runReport",+ ],+)+def test_non_retryable_errors_cover_runreport_client_errors(error_msg):+ # `_run_report` raises `response.raise_for_status()` verbatim for any runReport response+ # that isn't quota exhaustion or a 5xx (e.g. GA4 rejecting an invalid custom report+ # dimension/metric name with 400), so retrying replays the identical request forever.+ non_retryable_errors = GoogleAnalyticsSource().get_non_retryable_errors()+ assert error_message_matches(error_msg, non_retryable_errors)++def test_retryable_errors_cover_exhausted_quota_retries():error_msg = "Data API quota for property '123456789' still exhausted after 5 retries (retryable)"patterns = GoogleAnalyticsSource().get_retryable_errors()