diff --git a/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts b/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts index 7959d82b5f981..368f1372605d2 100644 --- a/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts +++ b/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts @@ -59,7 +59,12 @@ export default function useQueryEditor( [schemaOptions], ); - if ('schema' in queryEditor && schema && !schemaOptionsMap.has(schema)) { + if ( + 'schema' in queryEditor && + schemaOptions && + schema && + !schemaOptionsMap.has(schema) + ) { delete queryEditor.schema; } diff --git a/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts b/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts index e8db4bd361fbd..ad85a2554db13 100644 --- a/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts +++ b/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts @@ -116,3 +116,28 @@ test('skips the deprecated schema option', () => { expect(result.current.schema).not.toEqual(defaultQueryEditor.schema); expect(result.current.schema).toBeUndefined(); }); + +test('skips the deprecated schema option before loaded', () => { + const { result } = renderHook( + () => useQueryEditor(defaultQueryEditor.id, ['schema']), + { + wrapper: createWrapper({ + useRedux: true, + store: mockStore({ + ...initialState, + sqlLab: { + ...initialState.sqlLab, + queryEditors: [ + { + id: defaultQueryEditor.id, + schema: defaultQueryEditor.schema, + }, + ], + }, + }), + }), + }, + ); + expect(result.current.schema).toEqual(defaultQueryEditor.schema); + expect(result.current.schema).not.toBeUndefined(); +});