mirror of https://github.com/apache/superset.git
fix(sqllab): template validation error within comments (#25626)
This commit is contained in:
parent
4a01b6006c
commit
b370c66308
|
@ -25,6 +25,7 @@ from jinja2.meta import find_undeclared_variables
|
|||
|
||||
from superset import is_feature_enabled
|
||||
from superset.errors import SupersetErrorType
|
||||
from superset.sql_parse import ParsedQuery
|
||||
from superset.sqllab.commands.execute import SqlQueryRender
|
||||
from superset.sqllab.exceptions import SqlLabException
|
||||
from superset.utils import core as utils
|
||||
|
@ -57,8 +58,9 @@ class SqlQueryRenderImpl(SqlQueryRender):
|
|||
database=query_model.database, query=query_model
|
||||
)
|
||||
|
||||
parsed_query = ParsedQuery(query_model.sql, strip_comments=True)
|
||||
rendered_query = sql_template_processor.process_template(
|
||||
query_model.sql, **execution_context.template_params
|
||||
parsed_query.stripped(), **execution_context.template_params
|
||||
)
|
||||
self._validate(execution_context, rendered_query, sql_template_processor)
|
||||
return rendered_query
|
||||
|
|
|
@ -514,6 +514,13 @@ class TestSqlLab(SupersetTestCase):
|
|||
)
|
||||
assert data["status"] == "success"
|
||||
|
||||
data = self.run_sql(
|
||||
"SELECT * FROM birth_names WHERE state = '{{ state }}' -- blabblah {{ extra1 }} {{fake.fn()}}\nLIMIT 10",
|
||||
"3",
|
||||
template_params=json.dumps({"state": "CA"}),
|
||||
)
|
||||
assert data["status"] == "success"
|
||||
|
||||
data = self.run_sql(
|
||||
"SELECT * FROM birth_names WHERE state = '{{ stat }}' LIMIT 10",
|
||||
"2",
|
||||
|
|
Loading…
Reference in New Issue