: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(data-warehouse): mark Google Ads access_not_configured as non-retryable (#61584)
Tom Owers82a9ac0101b2
diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.pyindex ee35d6219d8b..75a4321d72c5 100644--- a/posthog/temporal/data_imports/sources/google_ads/source.py+++ b/posthog/temporal/data_imports/sources/google_ads/source.py@@ -51,6 +51,10 @@ class GoogleAdsSource(# has been revoked, expired, or is otherwise rejected by Google's token endpoint.# Retrying cannot recover — the user must reconnect their Google Ads account."invalid_grant": "Your Google Ads connection has expired or been revoked. Please reconnect your Google Ads account.",+ # google.auth.exceptions.RefreshError raised when the user's Google Workspace admin+ # has restricted third-party API access for this app (org policy / app not approved).+ # Retrying cannot recover — an admin must grant access before the user reconnects.+ "access_not_configured": "Your Google Workspace administrator has restricted API access for this app. Ask your admin to approve it, then reconnect your Google Ads account.",}# TODO: clean up google ads source to not have two auth config optionsdiff --git a/posthog/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/posthog/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.pyindex 6f6acf1854b2..7b6247802bd0 100644--- a/posthog/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py+++ b/posthog/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py@@ -24,6 +24,30 @@ class TestGoogleAdsNonRetryableErrors:f"RefreshError message {error_msg!r} did not match any non-retryable pattern")+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Real RefreshError strings observed in production when a Google Workspace+ # admin has restricted third-party API access for the app. Reported by+ # `str(e)` on google.auth.exceptions.RefreshError.+ (+ "('access_not_configured: Access to your account data (which may include HIPAA and PHI data) is "+ "restricted by policies within your organization. Please contact the administrator of your "+ "organization for more information regarding API access from third-party applications.', "+ "{'error': 'access_not_configured', 'error_description': 'Access to your account data ...'})"+ ),+ (+ "('access_not_configured: You can't access this app until an admin at your institution reviews "+ "and configures access for it. If you need access to this app,', {'error': 'access_not_configured', "+ "'error_description': 'You can't access this app ...'})"+ ),+ ],+ )+ def test_access_not_configured_is_non_retryable(self, error_msg):+ assert any(pattern in error_msg for pattern in self.non_retryable), (+ f"RefreshError message {error_msg!r} did not match any non-retryable pattern"+ )+@pytest.mark.parametrize("error_msg",[@@ -53,6 +77,9 @@ class TestGoogleAdsNonRetryableErrors:"UNAVAILABLE: The service is currently unavailable","ConnectionError: Connection reset by peer","INTERNAL: Internal server error",+ # A RefreshError wrapping a transient 502 from Google's token endpoint shares the+ # same error-tracking group as access_not_configured but must remain retryable.+ "('<!DOCTYPE html><title>Error 502 (Server Error)!!1</title>', None)",],)def test_transient_errors_are_retryable(self, error_msg):@@ -69,6 +96,7 @@ class TestGoogleAdsNonRetryableErrors:"INVALID_CUSTOMER_ID","REQUESTED_METRICS_FOR_MANAGER","invalid_grant",+ "access_not_configured",],)def test_documented_patterns_present(self, pattern):@@ -83,3 +111,8 @@ class TestGoogleAdsNonRetryableErrors:friendly = self.non_retryable["invalid_grant"]assert friendly is not Noneassert "reconnect" in friendly.lower()++ def test_access_not_configured_has_friendly_message(self):+ friendly = self.non_retryable["access_not_configured"]+ assert friendly is not None+ assert "admin" in friendly.lower()