: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
feat(data-warehouse): lift source onboarding conversion and fix Google OAuth source errors (#63527)
Tom Owers8bb15cb8201c
diff --git a/frontend/src/scenes/onboarding/onboardingLogic.test.ts b/frontend/src/scenes/onboarding/onboardingLogic.test.tsindex f7eb22105b45..f60a7675a6fb 100644--- a/frontend/src/scenes/onboarding/onboardingLogic.test.ts+++ b/frontend/src/scenes/onboarding/onboardingLogic.test.ts@@ -539,8 +539,8 @@ describe('onboardingLogic — flow composition', () => {describe('completion redirect URL', () => {// Each entry: [primary, expected redirect path-substring].// Verifies that each per-product provider's `completeRedirectUrl` is wired up.- // Two products (DATA_WAREHOUSE and EXPERIMENTS) intentionally fall through to- // urls.default() — same behaviour as the original central switch.+ // EXPERIMENTS intentionally falls through to urls.default() — same behaviour as+ // the original central switch.const cases: Array<[ProductKey, RegExp]> = [[ProductKey.PRODUCT_ANALYTICS, /quickstart|insight/i],[ProductKey.WEB_ANALYTICS, /web/i],@@ -551,6 +551,7 @@ describe('onboardingLogic — flow composition', () => {[ProductKey.AI_OBSERVABILITY, /ai-observability/i],[ProductKey.WORKFLOWS, /workflow/i],[ProductKey.LOGS, /log/i],+ [ProductKey.DATA_WAREHOUSE, /sources|data-management/i],]it.each(cases)('%s lands on a product-specific page', (product, pattern) => {@@ -558,11 +559,9 @@ describe('onboardingLogic — flow composition', () => {expect(logic.values.onCompleteOnboardingRedirectUrl).toMatch(pattern)})- it('experiments and data warehouse fall through to urls.default()', () => {+ it('experiments falls through to urls.default()', () => {logic.actions.setProductKey(ProductKey.EXPERIMENTS)expect(logic.values.onCompleteOnboardingRedirectUrl).toBe('/')- logic.actions.setProductKey(ProductKey.DATA_WAREHOUSE)- expect(logic.values.onCompleteOnboardingRedirectUrl).toBe('/')})it('redirect override takes precedence over the per-product URL', () => {diff --git a/posthog/temporal/data_imports/external_data_job.py b/posthog/temporal/data_imports/external_data_job.pyindex d231e17d003d..8c7ce8034287 100644--- a/posthog/temporal/data_imports/external_data_job.py+++ b/posthog/temporal/data_imports/external_data_job.py@@ -73,7 +73,7 @@ Any_Source_Errors: dict[str, str | None] = {"Could not establish session to SSH gateway": None,"Primary key required for incremental syncs": None,"The primary keys for this table are not unique": None,- "Integration matching query does not exist": None,+ "Integration matching query does not exist": "The connected account for this source is no longer available — it may have been disconnected. Please reconnect the source's account.",}diff --git a/posthog/temporal/data_imports/sources/google_ads/source.py b/posthog/temporal/data_imports/sources/google_ads/source.pyindex 2800a73824a8..062f718fd0cb 100644--- a/posthog/temporal/data_imports/sources/google_ads/source.py+++ b/posthog/temporal/data_imports/sources/google_ads/source.py@@ -275,4 +275,10 @@ class GoogleAdsSource(False,"The Google account is not associated with any Google Ads accounts. Please use an account with Google Ads access.",)+ if "matching query does not exist" in error_message:+ return (+ False,+ "Your Google Ads connection is no longer available — it may have been disconnected. "+ "Please reconnect your Google Ads account.",+ )return False, f"Error validating credentials: {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 d2a2e80d14d8..5a1ca5d377b8 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,5 +1,7 @@import pytest+from unittest import mock+from 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@@ -181,3 +183,19 @@ class TestGoogleAdsNonRetryableErrors:friendly = self.non_retryable["access_not_configured"]assert friendly is not Noneassert "admin" in friendly.lower()+++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+ # actionable reconnect message instead of the raw ORM error.+ with mock.patch(+ "posthog.temporal.data_imports.sources.google_ads.google_ads.google_ads_client",+ side_effect=Exception("Integration matching query does not exist"),+ ):+ ok, message = GoogleAdsSource().validate_credentials(config, team_id=1)++ assert ok is False+ assert "reconnect your Google Ads account" in (message or "")diff --git a/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py b/posthog/temporal/data_imports/sources/google_search_console/google_search_console.pyindex 899ae9391a9c..e79c9807209f 100644--- a/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py+++ b/posthog/temporal/data_imports/sources/google_search_console/google_search_console.py@@ -117,7 +117,13 @@ def _credentials(integration_id: int, team_id: int) -> OAuthCredentials:client_id=settings.GOOGLE_SEARCH_CONSOLE_APP_CLIENT_ID,client_secret=settings.GOOGLE_SEARCH_CONSOLE_APP_CLIENT_SECRET,token_uri="https://oauth2.googleapis.com/token",- scopes=["https://www.googleapis.com/auth/webmasters.readonly"],+ # No `scopes=` on purpose. With a refresh-token grant, google-auth forwards the+ # requested scopes to Google's token endpoint, which rejects anything that isn't an+ # exact subset of what the original consent granted — surfacing as+ # "invalid_scope: Bad Request" and failing every sync/validation. Omitting it+ # refreshes with the originally-granted scopes (matching the Google Ads client). A+ # genuinely missing scope then shows up as a 403 on the sites call, which we map to+ # an actionable "reconnect" message instead.)diff --git a/posthog/temporal/data_imports/sources/google_search_console/source.py b/posthog/temporal/data_imports/sources/google_search_console/source.pyindex b6ed2fc5c670..c2ab2727557d 100644--- a/posthog/temporal/data_imports/sources/google_search_console/source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/source.py@@ -104,6 +104,11 @@ class GoogleSearchConsoleSource(try:session = google_search_console_session(config.google_search_console_integration_id, team_id)except Exception as e:+ if "matching query does not exist" in str(e):+ return False, (+ "Your Google Search Console connection is no longer available — it may have been "+ "disconnected. Please reconnect your Google Search Console account."+ )return False, f"Could not load Google Search Console credentials: {e}"try:diff --git a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.pyindex 0c0283c315bd..2556457eaa30 100644--- a/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py+++ b/posthog/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py@@ -154,3 +154,17 @@ def test_validate_credentials_succeeds_for_verified_site():assert ok is Trueassert message is None+++def test_validate_credentials_handles_missing_integration():+ # A disconnected/deleted OAuth integration makes the credentials lookup raise+ # `Integration.DoesNotExist` ("... matching query does not exist"). Surface an+ # actionable reconnect message instead of the raw ORM error.+ with mock.patch(+ "posthog.temporal.data_imports.sources.google_search_console.source.google_search_console_session",+ side_effect=Exception("Integration matching query does not exist"),+ ):+ ok, message = GoogleSearchConsoleSource().validate_credentials(_config(), team_id=1)++ assert ok is False+ assert "reconnect your Google Search Console account" in (message or "")diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex 81f87854bba3..3a6933240653 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -110,7 +110,13 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDalabel="Host",type=SourceFieldInputConfigType.TEXT,required=True,- placeholder="localhost",+ placeholder="db.example.com",+ caption=(+ "Must be reachable from the public internet. Add PostHog's egress IP addresses to your "+ "firewall allowlist (see the docs above) and use a public host — `localhost` and private "+ "IPs (10.x, 172.16–31.x, 192.168.x) can't be reached. For a database that can't be "+ "exposed publicly, enable the SSH tunnel below."+ ),secret=False,),SourceFieldInputConfig(diff --git a/products/data_warehouse/frontend/onboarding/steps.tsx b/products/data_warehouse/frontend/onboarding/steps.tsxindex d7473bc02001..2265db224ad0 100644--- a/products/data_warehouse/frontend/onboarding/steps.tsx+++ b/products/data_warehouse/frontend/onboarding/steps.tsx@@ -1,11 +1,10 @@import { OnboardingDataWarehouseSourcesStep } from 'scenes/onboarding/data-warehouse/OnboardingDataWarehouseSourcesStep'import { type ProductOnboardingProvider } from 'scenes/onboarding/types'+import { urls } from 'scenes/urls'import { ProductKey } from '~/queries/schema/schema-general'import { OnboardingStepKey } from '~/types'-// `completeRedirectUrl` intentionally omitted: data warehouse falls through to-// urls.default() — same behaviour as the original central switch.export const dataWarehouseOnboarding: ProductOnboardingProvider = {steps: (ctx) => [{@@ -16,4 +15,8 @@ export const dataWarehouseOnboarding: ProductOnboardingProvider = {render: () => <OnboardingDataWarehouseSourcesStep />,},],+ // Land freshly-onboarded users on the sources list — where they can connect or manage a+ // source — instead of falling through to urls.default() (the home page), which drops the+ // data-warehouse intent on the floor. Every other product redirects to its own surface.+ completeRedirectUrl: () => urls.sources(),}