Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Select a query from History and Run #15891

Merged

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented Jul 25, 2021

SUMMARY

Fix an issue that SQL Lab didn't run correct sql after user pick a query from History. The root cause is that after update selected sql in redux store, component state is out of sync from props.

The proposed solution for this PR is to remove sql from component local state, and always use props which sync from redux store.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Step to reproduce:

  1. open sql lab
  2. run a sql statement
  3. pick a query from History tab
  4. you will see SQL Editor updated with the picked query
  5. Click Run button
  6. The query result is not correct: query result is actually from the previous sql statement.
    mIJImvnPa8

TESTING INSTRUCTIONS

CI and manual test.

@jinghua-qa It's a little troublesome to add unit test for this bug. Could you add a test case for this flow?

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

cc @etr2460 @ktmud

@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #15891 (4aec771) into master (9c81599) will increase coverage by 0.02%.
The diff coverage is 84.37%.

❗ Current head 4aec771 differs from pull request most recent head 349216b. Consider uploading reports for the commit 349216b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15891      +/-   ##
==========================================
+ Coverage   77.08%   77.11%   +0.02%     
==========================================
  Files         984      985       +1     
  Lines       51788    51849      +61     
  Branches     7037     7068      +31     
==========================================
+ Hits        39923    39983      +60     
- Misses      11640    11641       +1     
  Partials      225      225              
Flag Coverage Δ
javascript 71.79% <89.79%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...erset-frontend/src/SqlLab/components/SqlEditor.jsx 53.98% <0.00%> (+0.23%) ⬆️
superset/sql_lab.py 80.70% <40.00%> (+0.78%) ⬆️
superset/db_engine_specs/base.py 88.37% <50.00%> (-0.30%) ⬇️
...frontend/src/components/TimezoneSelector/index.tsx 97.77% <97.77%> (ø)
superset/db_engine_specs/hive.py 86.66% <100.00%> (+0.15%) ⬆️
superset/db_engine_specs/presto.py 90.37% <100.00%> (+0.06%) ⬆️
...d/src/explore/components/PropertiesModal/index.tsx 81.94% <0.00%> (-2.35%) ⬇️
superset-frontend/src/dataMask/reducer.ts 65.38% <0.00%> (-1.93%) ⬇️
...src/dashboard/components/FiltersBadge/selectors.ts 75.22% <0.00%> (-0.48%) ⬇️
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 41.04% <0.00%> (-0.44%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c81599...349216b. Read the comment docs.

@graceguo-supercat graceguo-supercat changed the title fix: Run query picked from History fix: Run sql picked from History Jul 26, 2021
Comment on lines 225 to 232
static getDerivedStateFromProps(props, state) {
if (props.queryEditor.sql !== state.sql) {
return {
sql: props.queryEditor.sql,
};
}
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needing to use this function seems a bit concerning... i'm referencing here: https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops:

If you want to “reset” some state when a prop changes, consider either making a component fully controlled or fully uncontrolled with a key instead.

I wonder if we can just use the sql from the queryEditor for everything here instead of using the state.sql string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is a good idea: I removed all the usage for state.sql and always use props.queryEditor.sql.

@graceguo-supercat graceguo-supercat changed the title fix: Run sql picked from History fix: Select a query from History and Run Jul 26, 2021
@etr2460
Copy link
Member

etr2460 commented Jul 26, 2021

/testenv up

@github-actions
Copy link
Contributor

@etr2460 Ephemeral environment spinning up at http://34.220.228.128:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm (and i couldn't break it in the test env). thanks for the fix and the iteration!

@graceguo-supercat graceguo-supercat merged commit 8c7e09e into apache:master Jul 27, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

serenajiang added a commit to serenajiang/incubator-superset that referenced this pull request Jul 30, 2021
serenajiang added a commit that referenced this pull request Jul 30, 2021
graceguo-supercat pushed a commit to airbnb/superset-fork that referenced this pull request Jul 31, 2021
serenajiang added a commit to airbnb/superset-fork that referenced this pull request Jul 31, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* fix: Run query picked from History

* remove sql from component local state
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* fix: Run query picked from History

* remove sql from component local state
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* fix: Run query picked from History

* remove sql from component local state
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* fix: Run query picked from History

* remove sql from component local state
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/S 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants