-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Changes from 6 commits
9b56534
1e09035
48ba8f6
6637471
ea2c1ae
bd42acc
46065e5
41735bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "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. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "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. | ||
|
||
from marshmallow import fields, Schema | ||
|
||
|
||
class SqlJsonPayloadSchema(Schema): | ||
database_id = fields.Integer(required=True) | ||
sql = fields.String(required=True) | ||
client_id = fields.String(allow_none=True) | ||
queryLimit = fields.Integer(allow_none=True) | ||
sql_editor_id = fields.String(allow_none=True) | ||
schema = fields.String(allow_none=True) | ||
tab = fields.String(allow_none=True) | ||
ctas_method = fields.String(allow_none=True) | ||
templateParams = fields.String(allow_none=True) | ||
tmp_table_name = fields.String(allow_none=True) | ||
select_as_cta = fields.Boolean(allow_none=True) | ||
json = fields.Boolean(allow_none=True) | ||
runAsync = fields.Boolean(allow_none=True) | ||
expand_data = fields.Boolean(allow_none=True) |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -763,6 +763,52 @@ def test_extra_table_metadata(self): | |||||||||||
f"/superset/extra_table_metadata/{example_db.id}/birth_names/{schema}/" | ||||||||||||
) | ||||||||||||
|
||||||||||||
def test_required_params_in_sql_json(self): | ||||||||||||
self.login() | ||||||||||||
client_id = "{}".format(random.getrandbits(64))[:10] | ||||||||||||
|
||||||||||||
data = {"client_id": client_id} | ||||||||||||
rv = self.client.post( | ||||||||||||
"/superset/sql_json/", | ||||||||||||
json=data, | ||||||||||||
) | ||||||||||||
failed_resp = { | ||||||||||||
"sql": ["Missing data for required field."], | ||||||||||||
"database_id": ["Missing data for required field."], | ||||||||||||
} | ||||||||||||
resp_data = json.loads(rv.data.decode("utf-8")) | ||||||||||||
self.assertDictEqual(resp_data, failed_resp) | ||||||||||||
self.assertEqual(rv.status_code, 400) | ||||||||||||
Comment on lines
+779
to
+781
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blocking, nits
Suggested change
|
||||||||||||
|
||||||||||||
data = {"sql": "SELECT 1", "client_id": client_id} | ||||||||||||
rv = self.client.post( | ||||||||||||
"/superset/sql_json/", | ||||||||||||
json=data, | ||||||||||||
) | ||||||||||||
failed_resp = {"database_id": ["Missing data for required field."]} | ||||||||||||
resp_data = json.loads(rv.data.decode("utf-8")) | ||||||||||||
self.assertDictEqual(resp_data, failed_resp) | ||||||||||||
self.assertEqual(rv.status_code, 400) | ||||||||||||
Comment on lines
+790
to
+791
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same before |
||||||||||||
|
||||||||||||
data = {"database_id": 1, "client_id": client_id} | ||||||||||||
rv = self.client.post( | ||||||||||||
"/superset/sql_json/", | ||||||||||||
json=data, | ||||||||||||
) | ||||||||||||
failed_resp = {"sql": ["Missing data for required field."]} | ||||||||||||
resp_data = json.loads(rv.data.decode("utf-8")) | ||||||||||||
self.assertDictEqual(resp_data, failed_resp) | ||||||||||||
self.assertEqual(rv.status_code, 400) | ||||||||||||
Comment on lines
+800
to
+801
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same before |
||||||||||||
|
||||||||||||
data = {"sql": "SELECT 1", "database_id": 1, "client_id": client_id} | ||||||||||||
rv = self.client.post( | ||||||||||||
"/superset/sql_json/", | ||||||||||||
json=data, | ||||||||||||
) | ||||||||||||
resp_data = json.loads(rv.data.decode("utf-8")) | ||||||||||||
self.assertEqual(resp_data.get("status"), "success") | ||||||||||||
self.assertEqual(rv.status_code, 200) | ||||||||||||
Comment on lines
+809
to
+810
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same before |
||||||||||||
|
||||||||||||
def test_templated_sql_json(self): | ||||||||||||
if superset.utils.database.get_example_database().backend == "presto": | ||||||||||||
# TODO: make it work for presto | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file necessary?