Skip to content

Commit

Permalink
fix(sqllab): infinite fetching status after results are landed (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored Nov 1, 2023
1 parent 1e37f0b commit 3f28eeb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
31 changes: 21 additions & 10 deletions superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,16 +667,27 @@ export default function sqlLabReducer(state = {}, action) {
[actions.CLEAR_INACTIVE_QUERIES]() {
const { queries } = state;
const cleanedQueries = Object.fromEntries(
Object.entries(queries).filter(([, query]) => {
if (
['running', 'pending'].includes(query.state) &&
Date.now() - query.startDttm > action.interval &&
query.progress === 0
) {
return false;
}
return true;
}),
Object.entries(queries)
.filter(([, query]) => {
if (
['running', 'pending'].includes(query.state) &&
Date.now() - query.startDttm > action.interval &&
query.progress === 0
) {
return false;
}
return true;
})
.map(([id, query]) => [
id,
{
...query,
state:
query.resultsKey && query.results?.status
? query.results.status
: query.state,
},
]),
);
return { ...state, queries: cleanedQueries };
},
Expand Down
35 changes: 35 additions & 0 deletions superset-frontend/src/SqlLab/reducers/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { QueryState } from '@superset-ui/core';
import sqlLabReducer from 'src/SqlLab/reducers/sqlLab';
import * as actions from 'src/SqlLab/actions/sqlLab';
import { table, initialState as mockState } from '../fixtures';
Expand Down Expand Up @@ -388,4 +389,38 @@ describe('sqlLabReducer', () => {
newState = sqlLabReducer(newState, actions.refreshQueries({}));
});
});
describe('CLEAR_INACTIVE_QUERIES', () => {
let newState;
let query;
beforeEach(() => {
query = {
id: 'abcd',
changed_on: Date.now(),
startDttm: Date.now(),
state: QueryState.FETCHING,
progress: 100,
resultsKey: 'fa3dccc4-c549-4fbf-93c8-b4fb5a6fb8b7',
cached: false,
};
});
it('updates queries that have already been completed', () => {
newState = sqlLabReducer(
{
...newState,
queries: {
abcd: {
...query,
results: {
query_id: 1234,
status: QueryState.SUCCESS,
data: [],
},
},
},
},
actions.clearInactiveQueries(Date.now()),
);
expect(newState.queries.abcd.state).toBe(QueryState.SUCCESS);
});
});
});

0 comments on commit 3f28eeb

Please sign in to comment.