You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/11/01 12:09:01 UTC
(superset) 03/03: fix(sqllab): infinite fetching status after results are landed (#25814)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 28272527fc7868cceae14e0e923c5936ba90c285
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Nov 1 05:03:03 2023 -0700
fix(sqllab): infinite fetching status after results are landed (#25814)
(cherry picked from commit 3f28eebb2061b53c0a15c24588261b6a71fbb799)
---
superset-frontend/src/SqlLab/reducers/sqlLab.js | 31 ++++++++++++-------
.../src/SqlLab/reducers/sqlLab.test.js | 35 ++++++++++++++++++++++
2 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js
index e6e0a54ed9..6e2db85a8b 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.js
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js
@@ -664,16 +664,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 };
},
diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js
index 89ddc61f8c..e1a234734b 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js
@@ -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';
@@ -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);
+ });
+ });
});