msyavuz commented on code in PR #36422:
URL: https://github.com/apache/superset/pull/36422#discussion_r2653028725
##########
tests/integration_tests/databases/api_tests.py:
##########
@@ -4104,6 +4104,130 @@ def test_validate_sql_endpoint_failure(self,
get_validator_by_name):
assert rv.status_code == 422
assert "Kaboom!" in response["errors"][0]["message"]
+ @mock.patch.dict(
+ "superset.config.SQL_VALIDATORS_BY_ENGINE",
+ SQL_VALIDATORS_BY_ENGINE,
+ clear=True,
+ )
+ def test_validate_sql_with_jinja_templates(self):
+ """
+ Database API: validate SQL with Jinja templates
+ """
+ request_payload = {
+ "sql": (
+ "SELECT *\nFROM birth_names\nWHERE 1=1\n"
+ "{% if city_filter is defined %}\n"
+ " AND city = '{{ city_filter }}'\n{% endif %}\n"
+ "LIMIT {{ limit | default(100) }}"
+ ),
+ "schema": None,
+ "template_params": {},
+ }
+
+ example_db = get_example_database()
+ if example_db.backend not in ("presto", "postgresql"):
+ pytest.skip("Only presto and PG are implemented")
+
+ self.login(ADMIN_USERNAME)
+ uri = f"api/v1/database/{example_db.id}/validate_sql/"
+ rv = self.client.post(uri, json=request_payload)
+ response = json.loads(rv.data.decode("utf-8"))
+ assert rv.status_code == 200
+ # Template was successfully rendered and validated
+ # For valid SQL, expect either an empty list or warnings (not errors)
+ result = response["result"]
+ assert isinstance(result, list)
+ # As a smoke check, ensure Jinja syntax was rendered
+ # (no '{' or '%' in error messages)
+ for error in result:
+ assert "{" not in error["message"]
+ assert "%" not in error["message"]
Review Comment:
Agreed with @pizofreude here. This creates a tight coupling between the
error message and the test. Let's check if we have any other way to determine
jinja errors here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]