: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_analytics): surface reconnect message when OAuth connection is gone (#73670)
Tom Owers503519bf0ed0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.pyindex b59f393df52a..556f89d38740 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py@@ -13,6 +13,8 @@ from posthog.schema import (SourceFieldOauthConfig,)+from posthog.models.integration import Integration+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import (SourceInputs,SourceResponse,@@ -149,6 +151,13 @@ class GoogleAnalyticsSource(ResumableSource[GoogleAnalyticsSourceConfig, GoogleAtry:session = google_analytics_session(config.google_analytics_integration_id, team_id)+ except Integration.DoesNotExist:+ # The stored OAuth integration row has been deleted/disconnected before validation runs.+ # Caught explicitly so an unrelated model's DoesNotExist still surfaces as a real bug below.+ return (+ False,+ "The Google Analytics connection for this source no longer exists. Please reconnect your Google account.",+ )except Exception as e:return False, f"Could not load Google Analytics credentials: {e}"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.pyindex 4412d9aaec3c..9d2c4912e47d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py@@ -6,6 +6,8 @@ from google.auth.exceptions import RefreshErrorfrom posthog.schema import ReleaseStatus, SourceFieldOauthConfig+from posthog.models.integration import Integration+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.googleanalytics import (GoogleAnalyticsSourceConfig,)@@ -225,6 +227,20 @@ def test_validate_credentials_handles_session_failure():assert "Could not load Google Analytics credentials" in (message or "")+def test_validate_credentials_handles_missing_integration():+ # A deleted/disconnected OAuth row makes `google_analytics_session` raise the typed+ # `Integration.DoesNotExist`; surface a reconnect message instead of the raw ORM error.+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.google_analytics_session",+ side_effect=Integration.DoesNotExist(),+ ):+ ok, message = GoogleAnalyticsSource().validate_credentials(_config(), team_id=1)++ assert ok is False+ assert "no longer exists" in (message or "")+ assert "matching query" not in (message or "")++def test_validate_credentials_succeeds_when_metadata_readable():with (mock.patch(