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(sqllab): template validation error within comments #25626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion superset/sqllab/query_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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
Expand Down Expand Up @@ -57,8 +58,9 @@ def render(self, execution_context: SqlJsonExecutionContext) -> str:
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
Expand Down
7 changes: 7 additions & 0 deletions tests/integration_tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ def test_sql_json_parameter_error(self):
)
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",
Expand Down
Loading