fix(sqllab): flaky json explore modal due to shallow equality checks for extra data (#29978)

This commit is contained in:
JUST.in DO IT 2024-08-22 07:28:08 +09:00 committed by GitHub
parent 7650c47e72
commit 1ca5947a7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

View File

@ -17,6 +17,8 @@
* under the License.
*/
import { normalizeTimestamp, QueryState, t } from '@superset-ui/core';
import { isEqual, omit } from 'lodash';
import { shallowEqual } from 'react-redux';
import * as actions from '../actions/sqlLab';
import { now } from '../../utils/dates';
import {
@ -696,7 +698,17 @@ export default function sqlLabReducer(state = {}, action) {
? prevState
: currentState,
};
change = true;
if (
shallowEqual(
omit(newQueries[id], ['extra']),
omit(state.queries[id], ['extra']),
) &&
isEqual(newQueries[id].extra, state.queries[id].extra)
) {
newQueries[id] = state.queries[id];
} else {
change = true;
}
}
});
if (!change) {

View File

@ -449,6 +449,35 @@ describe('sqlLabReducer', () => {
expect(newState.queries.abcd.endDttm).toBe(Number(endDttmInStr));
expect(newState.queriesLastUpdate).toBe(CHANGED_ON_TIMESTAMP);
});
it('should skip refreshing queries when polling contains existing results', () => {
const completedQuery = {
...query,
extra: {
columns: [],
progress: null,
},
};
newState = sqlLabReducer(
{
...newState,
queries: { abcd: query, def: completedQuery },
},
actions.refreshQueries({
abcd: {
...query,
},
def: {
...completedQuery,
extra: {
columns: [],
progress: null,
},
},
}),
);
expect(newState.queries.abcd).toBe(query);
expect(newState.queries.def).toBe(completedQuery);
});
it('should refresh queries when polling returns empty', () => {
newState = sqlLabReducer(newState, actions.refreshQueries({}));
});