fix: Changes ResultSet to include sqlEditorImmutableId when fetching results (#35773)

This commit is contained in:
Michael S. Molina
2025-10-21 14:24:39 -03:00
committed by GitHub
parent 4a3453999a
commit 337da13ba7
7 changed files with 55 additions and 6 deletions

View File

@@ -324,6 +324,7 @@ export type Query = {
schema?: string;
sql: string;
sqlEditorId: string;
sqlEditorImmutableId: string;
state: QueryState;
tab: string | null;
tempSchema: string | null;
@@ -373,6 +374,7 @@ export const testQuery: Query = {
dbId: 1,
sql: 'SELECT * FROM something',
sqlEditorId: 'dfsadfs',
sqlEditorImmutableId: 'immutableId2353',
tab: 'unimportant',
tempTable: '',
ctas: false,

View File

@@ -394,7 +394,7 @@ export function runQueryFromSqlEditor(
dbId: qe.dbId,
sql: qe.selectedText || qe.sql,
sqlEditorId: qe.tabViewId ?? qe.id,
immutableId: qe.immutableId,
sqlEditorImmutableId: qe.immutableId,
tab: qe.name,
catalog: qe.catalog,
schema: qe.schema,

View File

@@ -602,4 +602,42 @@ describe('ResultSet', () => {
);
expect(queryByTestId('copy-to-clipboard-button')).not.toBeInTheDocument();
});
test('should include sqlEditorImmutableId in query object when fetching results', async () => {
const queryWithResultsKey = {
...queries[0],
resultsKey: 'test-results-key',
sqlEditorImmutableId: 'test-immutable-id-123',
};
const store = mockStore({
...initialState,
user,
sqlLab: {
...initialState.sqlLab,
queries: {
[queryWithResultsKey.id]: queryWithResultsKey,
},
},
});
setup({ ...mockedProps, queryId: queryWithResultsKey.id }, store);
await waitFor(() => {
// Check that REQUEST_QUERY_RESULTS action was dispatched
const actions = store.getActions();
const requestAction = actions.find(
action => action.type === 'REQUEST_QUERY_RESULTS',
);
expect(requestAction).toBeDefined();
// Verify sqlEditorImmutableId is present in the query object
expect(requestAction?.query?.sqlEditorImmutableId).toBe(
'test-immutable-id-123',
);
});
// Verify the API was called
const resultsCalls = fetchMock.calls('glob:*/api/v1/sqllab/results/*');
expect(resultsCalls).toHaveLength(1);
});
});

View File

@@ -198,6 +198,7 @@ const ResultSet = ({
'sql',
'executedSql',
'sqlEditorId',
'sqlEditorImmutableId',
'templateParams',
'schema',
'rows',

View File

@@ -238,6 +238,7 @@ export const queries = [
ctas: false,
cached: false,
id: 'BkA1CLrJg',
sqlEditorImmutableId: 'BkA1CLrJg_immutable',
progress: 100,
startDttm: 1476910566092.96,
state: QueryState.Success,
@@ -297,6 +298,7 @@ export const queries = [
ctas: false,
cached: false,
id: 'S1zeAISkx',
sqlEditorImmutableId: 'S1zeAISkx_immutable',
progress: 100,
startDttm: 1476910570802.2,
state: QueryState.Success,
@@ -331,6 +333,7 @@ export const queryWithNoQueryLimit = {
ctas: false,
cached: false,
id: 'BkA1CLrJg',
sqlEditorImmutableId: 'BkA1CLrJg_immutable',
progress: 100,
startDttm: 1476910566092.96,
state: QueryState.Success,
@@ -589,6 +592,7 @@ const baseQuery: QueryResponse = {
ctas: false,
cached: false,
id: 'BkA1CLrJg',
sqlEditorImmutableId: 'BkA1CLrJg_immutable',
progress: 100,
startDttm: 1476910566092.96,
state: QueryState.Success,
@@ -672,6 +676,7 @@ export const runningQuery: QueryResponse = {
cached: false,
ctas: false,
id: 'ryhMUZCGb',
sqlEditorImmutableId: 'ryhMUZCGb_immutable',
progress: 90,
state: QueryState.Running,
startDttm: Date.now() - 500,
@@ -683,6 +688,7 @@ export const successfulQuery: QueryResponse = {
cached: false,
ctas: false,
id: 'ryhMUZCGb',
sqlEditorImmutableId: 'ryhMUZCGb_immutable',
progress: 100,
state: QueryState.Success,
startDttm: Date.now() - 500,

View File

@@ -208,14 +208,15 @@ const predicate = (actionType: string): AnyListenerPredicate<RootState> => {
// If we don't have a registration ID, don't filter events
if (!registrationImmutableId) return true;
// For query events, use the immutableId directly from the action payload
if (action.query?.immutableId) {
return action.query.immutableId === registrationImmutableId;
// For query events, use the sqlEditorImmutableId directly from the action payload
if (action.query?.sqlEditorImmutableId) {
return action.query.sqlEditorImmutableId === registrationImmutableId;
}
// For tab events, we need to find the immutable ID of the affected tab
if (action.queryEditor?.id) {
const queryEditor = findQueryEditor(action.queryEditor.id);
const queryEditorId = action.queryEditor?.id || action.query?.sqlEditorId;
if (queryEditorId) {
const queryEditor = findQueryEditor(queryEditorId);
return queryEditor?.immutableId === registrationImmutableId;
}

View File

@@ -66,6 +66,7 @@ export const mapQueryResponse = (
): Omit<
Query,
| 'tempSchema'
| 'sqlEditorImmutableId'
| 'started'
| 'time'
| 'duration'