: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): surface clear error when the connection no longer exists (#63528)
Tom Owers7b8687f0a035
diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.pyindex a739daac54c9..60991d1e60c6 100644--- a/posthog/temporal/data_imports/sources/google_ads/source.py+++ b/posthog/temporal/data_imports/sources/google_ads/source.py@@ -13,6 +13,7 @@ from posthog.schema import (SuggestedTable,)+from posthog.models.integration import Integrationfrom posthog.temporal.data_imports.pipelines.pipeline.typings import SourceInputs, SourceResponsefrom posthog.temporal.data_imports.sources.common.base import (MARKETING_ANALYTICS_SUGGESTED_TABLE_TOOLTIP,@@ -266,6 +267,11 @@ class GoogleAdsSource(f"Customer ID {config.customer_id} is not correct. Please check your customer ID and try again.",)return True, None+ except Integration.DoesNotExist:+ return (+ False,+ "The Google Ads connection for this source no longer exists. Please reconnect your Google Ads account.",+ )except Exception as e:error_message = str(e)if "ACCESS_TOKEN_SCOPE_INSUFFICIENT" in error_message: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.pyindex 5a1ca5d377b8..06aeb4245627 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@@ -1,6 +1,7 @@import pytestfrom unittest import mock+from posthog.models.integration import Integrationfrom posthog.temporal.data_imports.sources.generated_configs import GoogleAdsSourceConfigfrom posthog.temporal.data_imports.sources.google_ads.configs import clean_customer_idfrom posthog.temporal.data_imports.sources.google_ads.source import GoogleAdsSource@@ -186,11 +187,25 @@ class TestGoogleAdsNonRetryableErrors:class TestValidateCredentials:- def test_missing_integration_returns_friendly_message(self):- config = GoogleAdsSourceConfig(customer_id="123-456-7890", google_ads_integration_id=1)- # A disconnected/deleted OAuth integration makes the client builder raise- # `Integration.DoesNotExist` ("... matching query does not exist"). Surface an+ def test_missing_integration_does_not_exist_returns_reconnect_message(self):+ # `google_ads_client` calls `Integration.objects.get(...)`, which raises the typed+ # `Integration.DoesNotExist` when the OAuth connection row is gone. Surface an# actionable reconnect message instead of the raw ORM error.+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)+ with mock.patch(+ "posthog.temporal.data_imports.sources.google_ads.google_ads.google_ads_client",+ side_effect=Integration.DoesNotExist(),+ ):+ ok, message = GoogleAdsSource().validate_credentials(config, team_id=1)++ assert ok is False+ assert "no longer exists" in (message or "")+ assert "Integration matching query" not in (message or "")++ def test_missing_integration_string_match_returns_friendly_message(self):+ # The same condition can also surface as a generic exception whose message contains+ # the ORM "matching query does not exist" text; still surface a reconnect message.+ config = GoogleAdsSourceConfig(customer_id="123-456-7890", google_ads_integration_id=1)with mock.patch("posthog.temporal.data_imports.sources.google_ads.google_ads.google_ads_client",side_effect=Exception("Integration matching query does not exist"),