: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 deleted integration as non-retryable (#63693)
Tom Owers7d0ac6397192
diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.pyindex 60991d1e60c6..93328feec90a 100644--- a/posthog/temporal/data_imports/sources/google_ads/source.py+++ b/posthog/temporal/data_imports/sources/google_ads/source.py@@ -58,6 +58,11 @@ class GoogleAdsSource(# 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.",+ # Integration.DoesNotExist raised by `google_ads_client` when the stored OAuth+ # integration row has been deleted/disconnected before the sync runs. Retrying cannot+ # 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.",}# 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 06aeb4245627..bb4a49b44841 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@@ -137,6 +137,29 @@ class TestGoogleAdsNonRetryableErrors: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}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # `str(Integration.DoesNotExist)` as raised by `google_ads_client` during a sync when+ # the OAuth integration row has been deleted/disconnected.+ "Integration matching query does not exist.",+ ],+ )+ def test_missing_integration_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_integration_has_friendly_message(self):+ friendly = self.non_retryable["Integration matching query does not exist"]+ 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.+ error_msg = "ExternalDataSchema matching query does not exist."+ assert not any(pattern in error_msg for pattern in self.non_retryable.keys())+@pytest.mark.parametrize("error_msg",[