You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/07/18 17:52:52 UTC

(superset) branch master updated: fix(sqllab): preserve database state on SET_DATABASES (#41281)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new fb29db61192 fix(sqllab): preserve database state on SET_DATABASES (#41281)
fb29db61192 is described below

commit fb29db61192696eb5d585a4b6afc14afbb21c8c4
Author: Gagandeep Singh Choudhary <gc...@gmail.com>
AuthorDate: Sat Jul 18 23:22:45 2026 +0530

    fix(sqllab): preserve database state on SET_DATABASES (#41281)
    
    Co-authored-by: Joe Li <jo...@preset.io>
    Co-authored-by: Evan <ev...@preset.io>
    Co-authored-by: Claude Sonnet 5 <no...@anthropic.com>
---
 .../src/SqlLab/reducers/sqlLab.test.ts             | 35 +++++++++++++++++++++-
 superset-frontend/src/SqlLab/reducers/sqlLab.ts    |  8 ++++-
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.test.ts b/superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
index 717eed24e66..b3992223e40 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
@@ -21,13 +21,46 @@ import sqlLabReducer from 'src/SqlLab/reducers/sqlLab';
 import * as actions from 'src/SqlLab/actions/sqlLab';
 import type { SqlLabAction } from 'src/SqlLab/actions/sqlLab';
 import type { SqlLabRootState } from 'src/SqlLab/types';
-import { table, initialState as mockState } from '../fixtures';
+import { table, databases, initialState as mockState } from '../fixtures';
 
 type SqlLabState = SqlLabRootState['sqlLab'];
 const initialState = mockState.sqlLab as unknown as SqlLabState;
 
 // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
 describe('sqlLabReducer', () => {
+  test('should merge databases instead of replacing existing database state', () => {
+    const existingDb = {
+      ...databases.result[0],
+      extra: '{}',
+    };
+    const existingDbId = Number(existingDb.id);
+
+    const incomingDb = {
+      ...databases.result[0],
+      id: existingDbId + 1,
+      database_name: 'new database',
+      extra: '{}',
+    };
+    const incomingDbId = Number(incomingDb.id);
+
+    const state = {
+      ...initialState,
+      databases: {
+        [existingDbId]: existingDb,
+      },
+    } as any;
+
+    const action = actions.setDatabases([incomingDb] as any);
+
+    const newState = sqlLabReducer(state, action);
+
+    expect(newState.databases[existingDbId]).toEqual(existingDb);
+    expect(newState.databases[incomingDbId]).toEqual({
+      ...incomingDb,
+      extra_json: {},
+    });
+  });
+
   // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
   describe('Query editors actions', () => {
     let newState: SqlLabState;
diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.ts b/superset-frontend/src/SqlLab/reducers/sqlLab.ts
index bb8d5a0d343..7918079dd5e 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.ts
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.ts
@@ -729,7 +729,13 @@ export default function sqlLabReducer(
           extra_json: JSON.parse(db.extra || ''),
         };
       });
-      return { ...state, databases };
+      return {
+        ...state,
+        databases: {
+          ...state.databases,
+          ...databases,
+        },
+      };
     },
     [actions.REFRESH_QUERIES]() {
       let newQueries = { ...state.queries };