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

[sql_json] Ensuring the request body is JSON encoded #8256

Merged
merged 1 commit into from
Sep 23, 2019

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Sep 18, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Somewhat of a yak-shaving PR as the intent was to fix an issue where Hive queries failed in SQL Lab if no schema was selected,

Screen Shot 2019-09-18 at 3 54 58 PM

The error is coming from here in PyHive where it seems that the schema (database) is being defined via the "null" string as opposed to None.

The root cause of this is in the front-end the SupersetClient has passing the data as form data (using the multipart/form-data Content-Type header) which was then being processed in Flask via response.form. This meant everything was being encoded as strings, i.e., hence why we had logic like,

request.form.get("runAsync") == "true"

and why null was being encoded as "null" as opposed to None. The fix was to:

  1. Ensure that the front-end correctly encodes the body as JSON (and sets the appropriate headers).
  2. Use response.json to correctly process the response.
  3. Remove the obsolete GET method to sql_json.
  4. For testing use the somewhat misnamed json argument to Flask's test client.post(...) method which is actually a Python dictionary (ironically the data argument can be a JSON string) and removes the need to specify the Content-Type header (which is needed for response.json otherwise we would need to use response.get_json(force=True) which seems a little heavy handed).

TEST PLAN

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @etr2460 @graceguo-supercat @serenajiang @williaster
cc: @mistercrunch @villebro

endpoint: `/superset/sql_json/${window.location.search}`,
postPayload,
stringify: false,
endpoint: '/superset/sql_json/',
Copy link

@graceguo-supercat graceguo-supercat Sep 19, 2019

Choose a reason for hiding this comment

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

I saw this stringify: false setting is from PR #5896. @williaster is there a special reason to turn off stringify?

if use stringify, do we still need parseMethod: 'text'?

Copy link
Member

Choose a reason for hiding this comment

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

don't we really want stringify: false? I was under the impression that prevented us from sending up "null" and "false" versus null and false

And parseMethod determines how we parse the response, not the request

Choose a reason for hiding this comment

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

you will see we use post method in many, many places, only in sql lab added stringify: false. I assume there must be reason to do extra...

Copy link
Member

Choose a reason for hiding this comment

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

This is fine as it is, since we're setting body instead of postPayload, the stringify param is no longer used

endpoint: `/superset/sql_json/${window.location.search}`,
postPayload,
stringify: false,
endpoint: '/superset/sql_json/',
Copy link
Member

Choose a reason for hiding this comment

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

don't we really want stringify: false? I was under the impression that prevented us from sending up "null" and "false" versus null and false

And parseMethod determines how we parse the response, not the request

superset/views/core.py Show resolved Hide resolved
@dpgaspar
Copy link
Member

#8163 👀

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, thanks for the fix!

superset/views/core.py Show resolved Hide resolved
endpoint: `/superset/sql_json/${window.location.search}`,
postPayload,
stringify: false,
endpoint: '/superset/sql_json/',
Copy link
Member

Choose a reason for hiding this comment

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

This is fine as it is, since we're setting body instead of postPayload, the stringify param is no longer used

@john-bodley john-bodley force-pushed the john-bodley--fix-sql-json branch 2 times, most recently from 90c2678 to 19f0629 Compare September 19, 2019 20:29
@codecov-io
Copy link

Codecov Report

Merging #8256 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8256   +/-   ##
=======================================
  Coverage   65.66%   65.66%           
=======================================
  Files         481      481           
  Lines       23365    23365           
  Branches     2573     2573           
=======================================
  Hits        15342    15342           
  Misses       7885     7885           
  Partials      138      138
Impacted Files Coverage Δ
superset/assets/src/SqlLab/actions/sqlLab.js 61.13% <ø> (ø) ⬆️
superset/views/core.py 70.06% <100%> (ø) ⬆️

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 8bc5cd7...bc4150f. Read the comment docs.

@john-bodley john-bodley merged commit 5d1bf42 into apache:master Sep 23, 2019
@john-bodley john-bodley deleted the john-bodley--fix-sql-json branch September 23, 2019 16:09
@@ -220,9 +220,9 @@ export function runQuery(query) {
};

return SupersetClient.post({
endpoint: `/superset/sql_json/${window.location.search}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.35.0 labels Feb 28, 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 🚢 0.35.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants