Skip to content

Commit

Permalink
fix(sqllab): flaky json explore modal due to shallow equality checks …
Browse files Browse the repository at this point in the history
…for extra data (#29978)
  • Loading branch information
justinpark authored Aug 21, 2024
1 parent 7650c47 commit 1ca5947
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
14 changes: 13 additions & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions superset-frontend/src/SqlLab/reducers/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}));
});
Expand Down

0 comments on commit 1ca5947

Please sign in to comment.