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(sqllab): async query broken due to #21320 #21667

Merged
merged 4 commits into from
Oct 5, 2022

Conversation

justinpark
Copy link
Member

@justinpark justinpark commented Sep 30, 2022

SUMMARY

This commit fixes the async query broken issue on #21656

In #21320, it updated the following code

---624      runQuery={this.runQuery}
+++540      runQuery={startQuery}

which skips the following startQuery with empty args operation.

/// 422
  runQuery() {
    if (this.props.database) {
      this.startQuery();
    }
  }

This different payload broke the async query request.
This commit reverts back this origin logic.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

  • Before

Screen Shot 2022-09-30 at 2 00 34 PM

  • After

Screen Shot 2022-09-30 at 2 00 59 PM

TESTING INSTRUCTIONS

enable database option to async query execution
run the query

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

};

// hack the useMemo hook to imitate componentWillMount
useMemo(() => {
Copy link
Contributor

@eric-briscoe eric-briscoe Sep 30, 2022

Choose a reason for hiding this comment

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

Nice catch on finding cause of this bug!

I think the useEffect hook be more appropriate here and not be considered a hack, but recommended practice from React.

When using a
useEffect() => {
}, [])
`
With empty array it tells the functional component to only run the effect one time.

Notes section of: https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects

"If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument. This tells React that your effect doesn’t depend on any values from props or state, so it never needs to re-run. This isn’t handled as a special case — it follows directly from how the dependencies array always works."

Basically same exact code just swapping out the useMemo with useEffect to align with React's best practices and remove the hack comment

Copy link
Contributor

@EugeneTorap EugeneTorap Sep 30, 2022

Choose a reason for hiding this comment

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

@eric-briscoe am I correct
useMemo(() => {}, []); is componentWillMount event.
useEffect(() => {}, []); is componentDidMount event.
They are two different events.

Copy link
Contributor

Choose a reason for hiding this comment

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

@EugeneTorap useEffect is intended to replace all of the Class lifecycle methods so with functional components React is saying you no longer would try to differentiate between componentDidMount, componentDidUpdate, and componentWillUnmount, just use useEffect.

Tip If you’re familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and componentWillUnmount combined. https://reactjs.org/docs/hooks-effect.html

useMemo is for a very specific purpose and even React recommends not using it until you have a working component and start experience performance issues. useMemo runs during render and is not intended to produce side effects.

Remember that the function passed to useMemo runs during rendering. Don’t do anything there that you wouldn’t normally do while rendering. For example, side effects belong in useEffect, not useMemo. https://reactjs.org/docs/hooks-reference.html#usememo

@codecov
Copy link

codecov bot commented Sep 30, 2022

Codecov Report

Merging #21667 (82d473c) into master (4c17f0e) will decrease coverage by 0.00%.
The diff coverage is 16.66%.

@@            Coverage Diff             @@
##           master   #21667      +/-   ##
==========================================
- Coverage   66.82%   66.82%   -0.01%     
==========================================
  Files        1798     1799       +1     
  Lines       68827    68824       -3     
  Branches     7333     7315      -18     
==========================================
- Hits        45997    45994       -3     
+ Misses      20951    20945       -6     
- Partials     1879     1885       +6     
Flag Coverage Δ
javascript 53.15% <16.66%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...c/SqlLab/components/RunQueryActionButton/index.tsx 78.78% <ø> (+5.25%) ⬆️
...frontend/src/SqlLab/components/SqlEditor/index.jsx 55.67% <16.66%> (+1.32%) ⬆️
...d/src/SqlLab/components/SqlEditorLeftBar/index.tsx 50.74% <0.00%> (-3.54%) ⬇️
...src/filters/components/Range/RangeFilterPlugin.tsx 70.75% <0.00%> (-2.84%) ⬇️
superset-frontend/src/filters/utils.ts 92.10% <0.00%> (-2.64%) ⬇️
...d/src/SqlLab/components/ShareSqlLabQuery/index.tsx 80.76% <0.00%> (-1.99%) ⬇️
...frontend/src/components/DatabaseSelector/index.tsx 92.42% <0.00%> (-1.52%) ⬇️
...et-frontend/src/components/TableSelector/index.tsx 78.66% <0.00%> (-1.34%) ⬇️
...t-frontend/src/explore/actions/saveModalActions.js 97.26% <0.00%> (-1.34%) ⬇️
...uperset-frontend/src/components/FacePile/index.tsx 91.66% <0.00%> (-1.20%) ⬇️
... and 31 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@lyndsiWilliams
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

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

@zhaoyongjie zhaoyongjie self-requested a review October 3, 2022 03:54
Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

work as expected, tested in my local env. Thanks for the quick fix!

The master branch

async query - before

The current PR

async query - after

@EugeneTorap
Copy link
Contributor

@justinpark Can we try to cover it with RTL test?

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 4, 2022
@zhaoyongjie zhaoyongjie merged commit 50cb396 into apache:master Oct 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2022

Ephemeral environment shutdown and build artifacts deleted.

sadpandajoe added a commit to preset-io/superset that referenced this pull request Oct 17, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.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/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants