From 2199f65373c2ca9ccc51e1d2b046f14c1e801cdb Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Mon, 30 Aug 2021 15:47:00 -0700 Subject: [PATCH] fix: sql lab refetch button (#16469) * fix: SQL Lab show "Refetch Results" button while fetching new query results (#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments (cherry picked from commit 408d58f937a544190ca64d13942a6a7b04b95615) * handle exception caused by invalid query id --- superset-frontend/src/SqlLab/reducers/sqlLab.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index 9e423ba7c65b2..68de3ebd66d8c 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -520,7 +520,20 @@ export default function sqlLabReducer(state = {}, action) { if (changedQuery.changedOn > queriesLastUpdate) { queriesLastUpdate = changedQuery.changedOn; } - newQueries[id] = { ...state.queries[id], ...changedQuery }; + const prevState = state.queries[id]?.state; + const currentState = changedQuery.state; + newQueries[id] = { + ...state.queries[id], + ...changedQuery, + // race condition: + // because of async behavior, sql lab may still poll a couple of seconds + // when it started fetching or finished rendering results + state: + currentState === 'success' && + ['fetching', 'success'].includes(prevState) + ? prevState + : currentState, + }; change = true; } });