: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_ads): treat invalid-credentials 401 as non-retryable (#71431)
Tom Owersfad94a29877d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.pyindex 35d263031cad..6db4cd2900d0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py@@ -97,6 +97,10 @@ class GoogleAdsSource(# contains the bare "UNAUTHENTICATED" token, so the gRPC-status keys above don't catch it.# Retrying cannot recover — the user must reconnect their Google Ads account."Request is missing required authentication credential": "Your Google Ads connection could not be authenticated. Please reconnect your Google Ads account.",+ # The other gapic-wrapped Unauthenticated variant, str() "401 Request had invalid authentication+ # credentials. ..." — raised when the OAuth access token itself is rejected. Same story: no bare+ # "UNAUTHENTICATED" token, retrying cannot recover, the user must reconnect their Google Ads account.+ "Request had invalid authentication credentials": "Your Google Ads connection could not be authenticated. Please reconnect your Google Ads account.",}# TODO: clean up google ads source to not have two auth config optionsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.pyindex 56f0ca3db3ac..cf31e5098ac1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py@@ -215,14 +215,28 @@ class TestGoogleAdsNonRetryableErrors:"token, login cookie or other valid authentication credential. See ""https://developers.google.com/identity/sign-in/web/devconsole-project."),+ # The other gapic-wrapped Unauthenticated message, seen on the sync path when the OAuth+ # access token is rejected — same "401 {message}" shape, no bare UNAUTHENTICATED token.+ (+ "401 Request had invalid authentication credentials. Expected OAuth 2 access "+ "token, login cookie or other valid authentication credential. See "+ "https://developers.google.com/identity/sign-in/web/devconsole-project."+ ),],)def test_missing_auth_credential_is_non_retryable(self, error_msg):is_non_retryable = any(pattern in error_msg for pattern in self.non_retryable.keys())assert is_non_retryable, f"Expected error to be non-retryable: {error_msg}"- def test_missing_auth_credential_has_friendly_message(self):- friendly = self.non_retryable["Request is missing required authentication credential"]+ @pytest.mark.parametrize(+ "pattern",+ [+ "Request is missing required authentication credential",+ "Request had invalid authentication credentials",+ ],+ )+ def test_auth_credential_patterns_have_friendly_message(self, pattern):+ friendly = self.non_retryable[pattern]assert friendly is not Noneassert "reconnect" in friendly.lower()@@ -261,6 +275,7 @@ class TestGoogleAdsNonRetryableErrors:"invalid_grant","access_not_configured","Request is missing required authentication credential",+ "Request had invalid authentication credentials",],)def test_documented_patterns_present(self, pattern):