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(google_ads): treat missing OAuth credential as non-retryable (#65339)

Tom Owers0e16364bad4f
diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.py
index 93328feec90a..80a943cfee31 100644
--- a/posthog/temporal/data_imports/sources/google_ads/source.py
+++ b/posthog/temporal/data_imports/sources/google_ads/source.py
@@ -63,6 +63,11 @@ class GoogleAdsSource(
# recover — the user must reconnect their Google Ads account. Model-specific so we don't
# swallow unrelated `DoesNotExist` errors from other models, which may be real bugs.
"Integration matching query does not exist": "Your Google Ads connection is no longer available — it may have been disconnected. Please reconnect your Google Ads account.",
+ # gapic wraps a transport-level UNAUTHENTICATED into google.api_core.exceptions.Unauthenticated,
+ # whose str() is "401 Request is missing required authentication credential. ..." — it never
+ # 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.",
}
# TODO: clean up google ads source to not have two auth config options
diff --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.py
index 310c70bcb8b4..661a0f4d229f 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
@@ -169,6 +169,28 @@ class TestGoogleAdsNonRetryableErrors:
assert friendly is not None
assert "reconnect" in friendly.lower()
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # `str(google.api_core.exceptions.Unauthenticated)` as it propagates from
+ # `GoogleAdsService.search` — gapic wraps the transport-level UNAUTHENTICATED as
+ # "401 {message}", so it carries the human message but not the bare status token.
+ (
+ "401 Request is missing required authentication credential. 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"]
+ assert friendly is not None
+ assert "reconnect" in friendly.lower()
+
def test_other_model_does_not_exist_is_not_swallowed(self):
# The pattern is model-specific so an unrelated model's DoesNotExist — which may be a real
# bug — is not silently treated as non-retryable.
@@ -203,6 +225,7 @@ class TestGoogleAdsNonRetryableErrors:
"REQUESTED_METRICS_FOR_MANAGER",
"invalid_grant",
"access_not_configured",
+ "Request is missing required authentication credential",
],
)
def test_documented_patterns_present(self, pattern):