Skip to content

Commit 3f28eeb

Browse files
authored
fix(sqllab): infinite fetching status after results are landed (apache#25814)
1 parent 1e37f0b commit 3f28eeb

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

superset-frontend/src/SqlLab/reducers/sqlLab.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,16 +667,27 @@ export default function sqlLabReducer(state = {}, action) {
667667
[actions.CLEAR_INACTIVE_QUERIES]() {
668668
const { queries } = state;
669669
const cleanedQueries = Object.fromEntries(
670-
Object.entries(queries).filter(([, query]) => {
671-
if (
672-
['running', 'pending'].includes(query.state) &&
673-
Date.now() - query.startDttm > action.interval &&
674-
query.progress === 0
675-
) {
676-
return false;
677-
}
678-
return true;
679-
}),
670+
Object.entries(queries)
671+
.filter(([, query]) => {
672+
if (
673+
['running', 'pending'].includes(query.state) &&
674+
Date.now() - query.startDttm > action.interval &&
675+
query.progress === 0
676+
) {
677+
return false;
678+
}
679+
return true;
680+
})
681+
.map(([id, query]) => [
682+
id,
683+
{
684+
...query,
685+
state:
686+
query.resultsKey && query.results?.status
687+
? query.results.status
688+
: query.state,
689+
},
690+
]),
680691
);
681692
return { ...state, queries: cleanedQueries };
682693
},

superset-frontend/src/SqlLab/reducers/sqlLab.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import { QueryState } from '@superset-ui/core';
1920
import sqlLabReducer from 'src/SqlLab/reducers/sqlLab';
2021
import * as actions from 'src/SqlLab/actions/sqlLab';
2122
import { table, initialState as mockState } from '../fixtures';
@@ -388,4 +389,38 @@ describe('sqlLabReducer', () => {
388389
newState = sqlLabReducer(newState, actions.refreshQueries({}));
389390
});
390391
});
392+
describe('CLEAR_INACTIVE_QUERIES', () => {
393+
let newState;
394+
let query;
395+
beforeEach(() => {
396+
query = {
397+
id: 'abcd',
398+
changed_on: Date.now(),
399+
startDttm: Date.now(),
400+
state: QueryState.FETCHING,
401+
progress: 100,
402+
resultsKey: 'fa3dccc4-c549-4fbf-93c8-b4fb5a6fb8b7',
403+
cached: false,
404+
};
405+
});
406+
it('updates queries that have already been completed', () => {
407+
newState = sqlLabReducer(
408+
{
409+
...newState,
410+
queries: {
411+
abcd: {
412+
...query,
413+
results: {
414+
query_id: 1234,
415+
status: QueryState.SUCCESS,
416+
data: [],
417+
},
418+
},
419+
},
420+
},
421+
actions.clearInactiveQueries(Date.now()),
422+
);
423+
expect(newState.queries.abcd.state).toBe(QueryState.SUCCESS);
424+
});
425+
});
391426
});

0 commit comments

Comments
 (0)