You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2023/10/13 17:08:00 UTC

[superset] branch master updated: fix(sqllab): template validation error within comments (#25626)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b370c66308 fix(sqllab): template validation error within comments (#25626)
b370c66308 is described below

commit b370c66308e1bc84031ed7aae855aa72c20fbd11
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Fri Oct 13 13:07:54 2023 -0400

    fix(sqllab): template validation error within comments (#25626)
---
 superset/sqllab/query_render.py         | 4 +++-
 tests/integration_tests/sqllab_tests.py | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/superset/sqllab/query_render.py b/superset/sqllab/query_render.py
index 0852aaa891..4fb64c8ce2 100644
--- a/superset/sqllab/query_render.py
+++ b/superset/sqllab/query_render.py
@@ -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
diff --git a/tests/integration_tests/sqllab_tests.py b/tests/integration_tests/sqllab_tests.py
index 3b8941e556..03c3bdfc23 100644
--- a/tests/integration_tests/sqllab_tests.py
+++ b/tests/integration_tests/sqllab_tests.py
@@ -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",