: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): stop a double-clicked delete reporting a failure (#106753)
Tom Owersebcbb69611df
diff --git a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.tsindex 188edb22a7b7..39d4e3a760eb 100644--- a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts+++ b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts@@ -471,11 +471,28 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([actions.loadDatabase()},deleteSource: async ({ source }) => {- await api.externalDataSources.delete(source.id)- actions.loadSources()- actions.sourceLoadingFinished(source)+ // The confirm dialog stays clickable while it animates out, so a double click sends the+ // delete twice. The second request 404s on a source the first one already removed, which+ // surfaces as a failure for something that worked.+ const deleting: Set<string> = (cache.deletingSourceIds ??= new Set())+ if (deleting.has(source.id)) {+ return+ }+ deleting.add(source.id)- posthog.capture('source deleted', { sourceType: source.source_type })+ try {+ await api.externalDataSources.delete(source.id)+ // Only on success: a transient list failure resolves to an empty page, so reloading+ // after a delete that failed offline would blank a list of sources that still exist.+ actions.loadSources()+ posthog.capture('source deleted', { sourceType: source.source_type })+ } catch (e) {+ lemonToast.error("We couldn't delete this source. Refresh the page and try again.")+ posthog.captureException(e)+ } finally {+ deleting.delete(source.id)+ actions.sourceLoadingFinished(source)+ }},reloadSource: async ({ source }) => {// Optimistic UI updates before sending updates to the backenddiff --git a/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts b/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.tsindex 1ad4526c61ab..4d1cce45772a 100644--- a/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts+++ b/products/data_warehouse/frontend/shared/logics/tests/sourceManagementLogic.test.ts@@ -149,6 +149,39 @@ describe('sourceManagementLogic', () => {})})+ it('sends one delete when the confirm button is clicked twice', async () => {+ const source = { id: 'source-1', source_type: 'Stripe' } as ExternalDataSource+ let resolveDelete: (() => void) | undefined+ const deleteSource = jest+ .spyOn(api.externalDataSources, 'delete')+ .mockImplementation(() => new Promise<void>((resolve) => (resolveDelete = resolve)))++ logic.mount()+ logic.actions.deleteSource(source)+ logic.actions.deleteSource(source)++ expect(deleteSource).toHaveBeenCalledTimes(1)++ resolveDelete?.()+ await expectLogic(logic).toDispatchActions(['sourceLoadingFinished'])+ })++ it('stops the row spinner when the delete fails', async () => {+ const source = { id: 'source-1', source_type: 'Stripe' } as ExternalDataSource+ jest.spyOn(api.externalDataSources, 'delete').mockRejectedValue(new Error('boom'))++ logic.mount()+ await expectLogic(logic).toDispatchActions(['loadSourcesSuccess'])++ logic.actions.deleteSource(source)+ await expectLogic(logic).toDispatchActions(['sourceLoadingFinished'])++ expect(logic.values.sourceReloadingById['source-1']).toBe(false)+ // A transient list failure resolves to an empty page, so reloading after a failed delete+ // would blank a list of sources that still exist.+ expect(logic.values.dataWarehouseSourcesLoading).toBe(false)+ })+it('does not supersede an in-flight shallow schema load when mounted', async () => {let resolveShallowLoad: ((value: DatabaseSchemaQueryResponse) => void) | undefined;(performQuery as jest.Mock).mockImplementationOnce(