: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): guard databaseTableListLogic loader after await (#57671)
Sam Penningtonc9ac80f4da6b
diff --git a/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts b/frontend/src/scenes/data-management/database/databaseTableListLogic.test.tsindex b73e977a1d7b..b1a839badda9 100644--- a/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts+++ b/frontend/src/scenes/data-management/database/databaseTableListLogic.test.ts@@ -1,3 +1,5 @@+import posthog from 'posthog-js'+import { urls } from 'scenes/urls'import { performQuery } from '~/queries/query'@@ -67,6 +69,31 @@ describe('databaseTableListLogic', () => {expect(performQuery).toHaveBeenCalledTimes(1)})+ it.each([+ { name: 'main path', concurrentLoads: 1 },+ { name: 'dedup branch', concurrentLoads: 2 },+ ])('does not crash when unmounted mid-load ($name)', async ({ concurrentLoads }) => {+ let resolveQuery: ((value: { tables: Record<string, never>; joins: never[] }) => void) | undefined+ ;(performQuery as jest.Mock).mockImplementation(+ () =>+ new Promise((resolve) => {+ resolveQuery = resolve+ })+ )++ const localLogic = databaseTableListLogic()+ localLogic.mount()++ const requests = Array.from({ length: concurrentLoads }, () => localLogic.asyncActions.loadDatabase())+ expect(performQuery).toHaveBeenCalledTimes(1)++ localLogic.unmount()+ resolveQuery?.({ tables: {}, joins: [] })+ await Promise.all(requests)++ expect(posthog.captureException).not.toHaveBeenCalled()+ })+it('does not let a stale schema response overwrite the selected connection schema', async () => {let resolvePosthogQuery:| ((value: { tables: Record<string, { name: string; type: 'posthog' }>; joins: never[] }) => void)diff --git a/frontend/src/scenes/data-management/database/databaseTableListLogic.ts b/frontend/src/scenes/data-management/database/databaseTableListLogic.tsindex 7e681db4ef04..e445b548bb0b 100644--- a/frontend/src/scenes/data-management/database/databaseTableListLogic.ts+++ b/frontend/src/scenes/data-management/database/databaseTableListLogic.ts@@ -54,7 +54,12 @@ export const databaseTableListLogic = kea<databaseTableListLogicType>([const requestKey = requestConnectionId ?? '__posthog__'if (inFlightDatabaseLoadKey === requestKey && inFlightDatabaseLoadPromise) {- return await inFlightDatabaseLoadPromise+ const inFlight = inFlightDatabaseLoadPromise+ const result = await inFlight+ if (!databaseTableListLogic.isMounted()) {+ return null+ }+ return result}const request = performQuery(@@ -67,21 +72,27 @@ export const databaseTableListLogic = kea<databaseTableListLogicType>([inFlightDatabaseLoadKey = requestKeyinFlightDatabaseLoadPromise = request+ let database: Required<DatabaseSchemaQueryResponse> | null = nulltry {- const database = await request- const currentConnectionId = values.connectionId ?? undefined-- if (currentConnectionId !== requestConnectionId) {- return values.database- }-- return database+ database = await request} finally {if (inFlightDatabaseLoadKey === requestKey) {inFlightDatabaseLoadKey = nullinFlightDatabaseLoadPromise = null}}++ // Reading `values` post-unmount throws kea's path-not-found error.+ if (!databaseTableListLogic.isMounted()) {+ return null+ }++ const currentConnectionId = values.connectionId ?? undefined+ if (currentConnectionId !== requestConnectionId) {+ return values.database+ }++ return database},},],