From a51f6274932850b245a47e345a163f243551f525 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Wed, 24 Jun 2026 17:29:46 -0700 Subject: [PATCH 1/2] fix(sqllab): preserve query history after tab migration --- .../src/SqlLab/actions/sqlLab.test.ts | 19 ++++++++++++++++++- .../src/SqlLab/actions/sqlLab.ts | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts index ae53c83b77a4..33274c6ec414 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts @@ -1852,6 +1852,18 @@ describe('async actions', () => { sqlEditorId: oldQueryEditor.id, inLocalStorage: true, }, + { + ...query, + id: 'runningQuery', + sqlEditorId: oldQueryEditor.id, + state: 'running', + }, + { + ...query, + id: 'unrelatedQuery', + sqlEditorId: 'other-editor', + state: 'running', + }, ]; const store = mockStore({ sqlLab: { @@ -1893,6 +1905,11 @@ describe('async actions', () => { queryId: 'previewTwo', queryEditorId: '1', }, + { + type: actions.MIGRATE_QUERY, + queryId: 'runningQuery', + queryEditorId: '1', + }, ]; return store .dispatch(actions.syncQueryEditor(oldQueryEditor)) @@ -1900,7 +1917,7 @@ describe('async actions', () => { expect(store.getActions()).toEqual(expectedActions); expect( fetchMock.callHistory.calls(updateTabStateEndpoint), - ).toHaveLength(3); + ).toHaveLength(4); // query editor has 2 tables loaded in the schema viewer expect( diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.ts b/superset-frontend/src/SqlLab/actions/sqlLab.ts index 072bfd05260e..8941f688929b 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.ts +++ b/superset-frontend/src/SqlLab/actions/sqlLab.ts @@ -689,8 +689,8 @@ export function syncQueryEditor( (table: Table) => table.inLocalStorage && table.queryEditorId === queryEditor.id, ); - const localStorageQueries = Object.values(queries).filter( - query => query.inLocalStorage && query.sqlEditorId === queryEditor.id, + const queriesToMigrate = Object.values(queries).filter( + query => query.sqlEditorId === queryEditor.id && !query.isDataPreview, ); return SupersetClient.post({ endpoint: '/tabstateview/', @@ -712,7 +712,7 @@ export function syncQueryEditor( ...localStorageTables.map((table: Table) => migrateTable(table, newQueryEditor.tabViewId!, dispatch), ), - ...localStorageQueries.map((query: Query) => + ...queriesToMigrate.map((query: Query) => migrateQuery(query.id, newQueryEditor.tabViewId!, dispatch), ), ]); From a2241b13419969503a980e48edef75a619fa0642 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Thu, 25 Jun 2026 11:17:22 -0700 Subject: [PATCH 2/2] test(sqllab): cover preview query migration --- .../src/SqlLab/actions/sqlLab.test.ts | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts index 33274c6ec414..157aaa3d4c9f 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts @@ -1843,14 +1843,14 @@ describe('async actions', () => { { ...query, id: 'previewOne', - sqlEditorId: oldQueryEditor.id, - inLocalStorage: true, + sqlEditorId: null, + isDataPreview: true, }, { ...query, id: 'previewTwo', - sqlEditorId: oldQueryEditor.id, - inLocalStorage: true, + sqlEditorId: null, + isDataPreview: true, }, { ...query, @@ -1895,16 +1895,6 @@ describe('async actions', () => { // new table has a different id and points to new query editor newTable: { ...tables[1], id: 1, queryEditorId: '1' }, }, - { - type: actions.MIGRATE_QUERY, - queryId: 'previewOne', - queryEditorId: '1', - }, - { - type: actions.MIGRATE_QUERY, - queryId: 'previewTwo', - queryEditorId: '1', - }, { type: actions.MIGRATE_QUERY, queryId: 'runningQuery', @@ -1917,7 +1907,7 @@ describe('async actions', () => { expect(store.getActions()).toEqual(expectedActions); expect( fetchMock.callHistory.calls(updateTabStateEndpoint), - ).toHaveLength(4); + ).toHaveLength(2); // query editor has 2 tables loaded in the schema viewer expect(