mirror of https://github.com/apache/superset.git
accept null params for validation (#17788)
This commit is contained in:
parent
dc50578f7f
commit
b82da5c016
|
@ -2412,7 +2412,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||
schema = request.form.get("schema") or None
|
||||
template_params = json.loads(request.form.get("templateParams") or "{}")
|
||||
|
||||
if len(template_params) > 0:
|
||||
if template_params is not None and len(template_params) > 0:
|
||||
# TODO: factor the Database object out of template rendering
|
||||
# or provide it as mydb so we can render template params
|
||||
# without having to also persist a Query ORM object.
|
||||
|
|
|
@ -458,6 +458,7 @@ class SupersetTestCase(TestCase):
|
|||
user_name=None,
|
||||
raise_on_error=False,
|
||||
database_name="examples",
|
||||
template_params=None,
|
||||
):
|
||||
if user_name:
|
||||
self.logout()
|
||||
|
@ -466,7 +467,12 @@ class SupersetTestCase(TestCase):
|
|||
resp = self.get_json_resp(
|
||||
"/superset/validate_sql_json/",
|
||||
raise_on_error=False,
|
||||
data=dict(database_id=dbid, sql=sql, client_id=client_id),
|
||||
data=dict(
|
||||
database_id=dbid,
|
||||
sql=sql,
|
||||
client_id=client_id,
|
||||
templateParams=template_params,
|
||||
),
|
||||
)
|
||||
if raise_on_error and "error" in resp:
|
||||
raise Exception("validate_sql failed")
|
||||
|
|
|
@ -94,6 +94,37 @@ class TestSqlValidatorEndpoint(SupersetTestCase):
|
|||
self.assertEqual(1, len(resp))
|
||||
self.assertIn("expected,", resp[0]["message"])
|
||||
|
||||
@patch("superset.views.core.get_validator_by_name")
|
||||
@patch.dict(
|
||||
"superset.config.SQL_VALIDATORS_BY_ENGINE",
|
||||
PRESTO_SQL_VALIDATORS_BY_ENGINE,
|
||||
clear=True,
|
||||
)
|
||||
def test_validate_sql_endpoint_mocked_params(self, get_validator_by_name):
|
||||
"""Assert that, with a mocked validator, annotations make it back out
|
||||
from the validate_sql_json endpoint as a list of json dictionaries"""
|
||||
if get_example_database().backend == "hive":
|
||||
pytest.skip("Hive validator is not implemented")
|
||||
self.login("admin")
|
||||
|
||||
validator = MagicMock()
|
||||
get_validator_by_name.return_value = validator
|
||||
validator.validate.return_value = [
|
||||
SQLValidationAnnotation(
|
||||
message="This worked", line_number=4, start_column=12, end_column=42,
|
||||
)
|
||||
]
|
||||
|
||||
resp = self.validate_sql(
|
||||
"SELECT * FROM somewhere_over_the_rainbow",
|
||||
client_id="1",
|
||||
raise_on_error=False,
|
||||
template_params="null",
|
||||
)
|
||||
|
||||
self.assertEqual(1, len(resp))
|
||||
self.assertNotIn("error,", resp[0]["message"])
|
||||
|
||||
@patch("superset.views.core.get_validator_by_name")
|
||||
@patch.dict(
|
||||
"superset.config.SQL_VALIDATORS_BY_ENGINE",
|
||||
|
|
Loading…
Reference in New Issue