: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(data-warehouse): ignore a stale schema probe after switching sources (#119013)
Tom Owersdfc042225611
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsxindex a8fc504e77d5..a6143dfd644e 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx@@ -460,6 +460,7 @@ export interface sourceWizardLogicValues {cdcSelfManagedVerifyResultLoading: booleanconfiguredSchemaName: string | nullconnectError: string | null+ connectorSelectionCount: numberconnectors: SourceConfigResponseApi[]currentStep: numbercurrentSyncMethodModalSchema: ExternalDataSourceSyncSchema | null@@ -1354,6 +1355,15 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([{onNext: () => false,setIsLoading: (_, { isLoading }) => isLoading,+ selectConnector: () => false,+ },+ ],+ // Counts selections rather than comparing connector objects, so picking the same source+ // again (A, then B, then A) still marks an earlier in-flight probe as stale.+ connectorSelectionCount: [+ 0,+ {+ selectConnector: (count) => count + 1,},],// The toast that also carries this message is gone in a few seconds, so people retry the@@ -2428,6 +2438,10 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([actions.setIsLoading(true)const sourceType = values.selectedConnector.name+ // The logic is not keyed per connector, so a slow probe can finish after the user picks+ // another source. Its result then belongs to no visible form and must not reach the UI.+ const selection = values.connectorSelectionCount+ const connectorChanged = (): boolean => values.connectorSelectionCount !== selectionconst startedAt = performance.now()const captureSchemasLoaded = (success: boolean, schemaCount: number | null): void => {posthog.capture('source wizard schemas loaded', {@@ -2446,6 +2460,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([throw e})captureSchemasLoaded(true, schemas.length)+ if (connectorChanged()) {+ return+ }// Backend `cdc_available` only reflects the team flag — clear it when the// user didn't toggle CDC on for this source in step 1.@@ -2581,6 +2598,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([actions.setDatabaseSchemas(schemas)actions.onNext()} catch (e: any) {+ if (connectorChanged()) {+ return+ }const apiMessage = e.data?.message ?? e.detailconst errorMessage = resolveConnectErrorMessage(e)actions.setConnectError(errorMessage)diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.tsindex efe496355f8e..15d9614cbc98 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts@@ -3,6 +3,8 @@ import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'import { expectLogic } from 'kea-test-utils'import posthog from 'posthog-js'+import { lemonToast } from '@posthog/lemon-ui'+import api from 'lib/api'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'@@ -27,6 +29,11 @@ import {WIZARD_DESTINATION_STEP,} from '../sourceWizardLogic'+type Deferred = {+ resolve: (schemas: ExternalDataSourceSyncSchema[]) => void+ reject: (error: unknown) => void+}+function buildSourceConfig(overrides: Partial<SourceConfigResponseApi>): SourceConfigResponseApi {// Fills the fields the wizard endpoint always sends but no case here exercises, so each// fixture states only what it is about.@@ -1637,5 +1644,59 @@ describe('sourceWizardLogic', () => {unmount()}})++ const sentrySource = buildSourceConfig({ name: 'Sentry' })+ const rejectProbe = (d: Deferred): void => d.reject({ status: 400, data: { message: 'Bad key.' } })+ const resolveProbe = (d: Deferred): void => d.resolve([{ table: 'charges' } as ExternalDataSourceSyncSchema])++ it.each([+ { outcome: 'rejects', picked: 'another source', switchTo: [sentrySource], settle: rejectProbe },+ { outcome: 'resolves', picked: 'another source', switchTo: [sentrySource], settle: resolveProbe },+ {+ outcome: 'rejects',+ picked: 'the same source again',+ switchTo: [sentrySource, stripeSource],+ settle: rejectProbe,+ },+ {+ outcome: 'resolves',+ picked: 'the same source again',+ switchTo: [sentrySource, stripeSource],+ settle: resolveProbe,+ },+ ])('ignores a probe that $outcome after $picked is picked', async ({ switchTo, settle }) => {+ const deferred = {} as Deferred+ jest.spyOn(api.externalDataSources, 'database_schema').mockReturnValue(+ new Promise<ExternalDataSourceSyncSchema[]>((resolve, reject) =>+ Object.assign(deferred, { resolve, reject })+ )+ )+ const toastError = jest.spyOn(lemonToast, 'error')++ const logic = sourceWizardLogic({ availableSources: { Stripe: stripeSource, Sentry: sentrySource } })+ const unmount = logic.mount()++ try {+ logic.actions.selectConnector(stripeSource)+ logic.actions.setStep(2)+ logic.actions.getDatabaseSchemas()+ for (const source of switchTo) {+ logic.actions.selectConnector(source)+ }+ expect(logic.values.isLoading).toBe(false)+ settle(deferred)+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values).toMatchObject({+ currentStep: 2,+ connectError: null,+ databaseSchema: [],+ isLoading: false,+ })+ expect(toastError).not.toHaveBeenCalled()+ } finally {+ unmount()+ }+ })})})