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: Validate required fields in sql_json API #21003

Merged
merged 8 commits into from
Aug 11, 2022
Merged

fix: Validate required fields in sql_json API #21003

merged 8 commits into from
Aug 11, 2022

Conversation

EugeneTorap
Copy link
Contributor

fix #20873 issues.

SUMMARY

sql_json API has two required fields:

  • sql: string
  • database_id: integer

We need to validate these fields if they are None and send user an understandable error if one of the fields is missing.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@codecov
Copy link

codecov bot commented Aug 7, 2022

Codecov Report

Merging #21003 (e09b951) into master (e214e1a) will decrease coverage by 0.15%.
The diff coverage is 73.20%.

❗ Current head e09b951 differs from pull request most recent head 41735bf. Consider uploading reports for the commit 41735bf to get more accurate results

@@            Coverage Diff             @@
##           master   #21003      +/-   ##
==========================================
- Coverage   66.34%   66.18%   -0.16%     
==========================================
  Files        1767     1768       +1     
  Lines       67312    67367      +55     
  Branches     7144     7144              
==========================================
- Hits        44656    44586      -70     
- Misses      20828    20953     +125     
  Partials     1828     1828              
Flag Coverage Δ
hive ?
mysql 80.95% <93.93%> (+0.02%) ⬆️
postgres 81.00% <93.93%> (+0.01%) ⬆️
presto ?
python 81.12% <93.93%> (-0.36%) ⬇️
sqlite 79.61% <93.93%> (+0.02%) ⬆️
unit ?

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

Impacted Files Coverage Δ
...packages/superset-ui-core/src/query/types/Query.ts 100.00% <ø> (ø)
...ackages/superset-ui-core/src/utils/featureFlags.ts 100.00% <ø> (ø)
...rts/src/BigNumber/BigNumberTotal/transformProps.ts 0.00% <0.00%> (ø)
...lugin-chart-echarts/src/BigNumber/BigNumberViz.tsx 0.00% <0.00%> (ø)
...lugin-chart-echarts/src/BoxPlot/EchartsBoxPlot.tsx 0.00% <0.00%> (ø)
.../plugins/plugin-chart-echarts/src/BoxPlot/types.ts 0.00% <ø> (ø)
.../plugin-chart-echarts/src/Funnel/EchartsFunnel.tsx 0.00% <0.00%> (ø)
...d/plugins/plugin-chart-echarts/src/Funnel/types.ts 100.00% <ø> (ø)
...ns/plugin-chart-echarts/src/Gauge/EchartsGauge.tsx 0.00% <0.00%> (ø)
...ns/plugin-chart-echarts/src/Graph/EchartsGraph.tsx 0.00% <0.00%> (ø)
... and 96 more

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

@EugeneTorap
Copy link
Contributor Author

@hughhhh @betodealmeida Can you review it?

@zhaoyongjie
Copy link
Member

Hi @EugeneTorap, Thanks for adding validation on the endpoint. Do you mind following the Mashmallow validation schema for the requesting validation? Here are some examples.

@EugeneTorap
Copy link
Contributor Author

Hi @EugeneTorap, Thanks for adding validation on the endpoint. Do you mind following the Mashmallow validation schema for the requesting validation? Here are some examples.

Thanks, will do it

@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 11, 2022
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.

LGTM! Thanks for the restructuring modules and adding more tests for key functions!

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.

sorry, left some no-blocking comments in the test case.

Comment on lines +790 to +791
self.assertDictEqual(resp_data, failed_resp)
self.assertEqual(rv.status_code, 400)
Copy link
Member

Choose a reason for hiding this comment

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

same before

Comment on lines +800 to +801
self.assertDictEqual(resp_data, failed_resp)
self.assertEqual(rv.status_code, 400)
Copy link
Member

Choose a reason for hiding this comment

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

same before

Comment on lines +809 to +810
self.assertEqual(resp_data.get("status"), "success")
self.assertEqual(rv.status_code, 200)
Copy link
Member

Choose a reason for hiding this comment

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

same before

Comment on lines +779 to +781
resp_data = json.loads(rv.data.decode("utf-8"))
self.assertDictEqual(resp_data, failed_resp)
self.assertEqual(rv.status_code, 400)
Copy link
Member

Choose a reason for hiding this comment

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

no blocking, nits

Suggested change
resp_data = json.loads(rv.data.decode("utf-8"))
self.assertDictEqual(resp_data, failed_resp)
self.assertEqual(rv.status_code, 400)
assert rv.json == failed_resp
assert rv.status_code == 400

@zhaoyongjie zhaoyongjie merged commit a2b21b5 into apache:master Aug 11, 2022
@EugeneTorap EugeneTorap deleted the fix/validate-sql_json-api branch August 11, 2022 15:47
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
Copy link
Member

Choose a reason for hiding this comment

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

Is this file necessary?

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 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/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate request fields in sql_json API
4 participants