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

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

commit f9c0171b999b7541ad90acb2b5f4bc374895709c
Author: John Bodley <[email protected]>
AuthorDate: Wed Apr 3 19:24:39 2024 -0700

    chore(sqllab): Do not strip comments when executing SQL statements (#27725)
---
 superset/sql_lab.py                            |  1 -
 tests/integration_tests/databases/api_tests.py | 14 +++++-----
 tests/integration_tests/sqllab_tests.py        | 37 +++++++++++++++-----------
 3 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index e9b4d406f8..059e436962 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -422,7 +422,6 @@ def execute_sql_statements(
     # Breaking down into multiple statements
     parsed_query = ParsedQuery(
         rendered_query,
-        strip_comments=True,
         engine=db_engine_spec.engine,
     )
     if not db_engine_spec.run_multiple_statements_as_one:
diff --git a/tests/integration_tests/databases/api_tests.py 
b/tests/integration_tests/databases/api_tests.py
index 9d28bd941b..e1cf2f55dc 100644
--- a/tests/integration_tests/databases/api_tests.py
+++ b/tests/integration_tests/databases/api_tests.py
@@ -1280,7 +1280,7 @@ class TestDatabaseApi(SupersetTestCase):
                     "indexes": [],
                     "name": "wrong_table",
                     "primaryKey": {"constrained_columns": None, "name": None},
-                    "selectStar": "SELECT\n  *\nFROM wrong_table\nLIMIT 
100\nOFFSET 0",
+                    "selectStar": "SELECT\nFROM wrong_table\nLIMIT 100\nOFFSET 
0",
                 },
             )
         elif example_db.backend == "mysql":
@@ -2293,9 +2293,9 @@ class TestDatabaseApi(SupersetTestCase):
         uri = "api/v1/database/import/"
 
         masked_database_config = database_config.copy()
-        masked_database_config[
-            "sqlalchemy_uri"
-        ] = "postgresql://username:XXXXXXXXXX@host:12345/db"
+        masked_database_config["sqlalchemy_uri"] = (
+            "postgresql://username:XXXXXXXXXX@host:12345/db"
+        )
 
         buf = BytesIO()
         with ZipFile(buf, "w") as bundle:
@@ -2350,9 +2350,9 @@ class TestDatabaseApi(SupersetTestCase):
         uri = "api/v1/database/import/"
 
         masked_database_config = database_config.copy()
-        masked_database_config[
-            "sqlalchemy_uri"
-        ] = 
"vertica+vertica_python://hackathon:XXXXXXXXXX@host:5433/dbname?ssl=1"
+        masked_database_config["sqlalchemy_uri"] = (
+            
"vertica+vertica_python://hackathon:XXXXXXXXXX@host:5433/dbname?ssl=1"
+        )
 
         buf = BytesIO()
         with ZipFile(buf, "w") as bundle:
diff --git a/tests/integration_tests/sqllab_tests.py 
b/tests/integration_tests/sqllab_tests.py
index 03c3bdfc23..b54d018894 100644
--- a/tests/integration_tests/sqllab_tests.py
+++ b/tests/integration_tests/sqllab_tests.py
@@ -18,6 +18,7 @@
 """Unit tests for Sql Lab"""
 import json
 from datetime import datetime
+from textwrap import dedent
 
 import pytest
 from celery.exceptions import SoftTimeLimitExceeded
@@ -578,12 +579,13 @@ class TestSqlLab(SupersetTestCase):
     @mock.patch("superset.sql_lab.get_query")
     @mock.patch("superset.sql_lab.execute_sql_statement")
     def test_execute_sql_statements(self, mock_execute_sql_statement, 
mock_get_query):
-        sql = """
+        sql = dedent(
+            """
             -- comment
             SET @value = 42;
-            SELECT @value AS foo;
-            -- comment
+            SELECT /*+ hint */ @value AS foo;
         """
+        )
         mock_session = mock.MagicMock()
         mock_query = mock.MagicMock()
         mock_query.database.allow_run_async = False
@@ -607,7 +609,7 @@ class TestSqlLab(SupersetTestCase):
         mock_execute_sql_statement.assert_has_calls(
             [
                 mock.call(
-                    "SET @value = 42",
+                    "-- comment\nSET @value = 42",
                     mock_query,
                     mock_session,
                     mock_cursor,
@@ -615,7 +617,7 @@ class TestSqlLab(SupersetTestCase):
                     False,
                 ),
                 mock.call(
-                    "SELECT @value AS foo",
+                    "SELECT /*+ hint */ @value AS foo",
                     mock_query,
                     mock_session,
                     mock_cursor,
@@ -631,12 +633,13 @@ class TestSqlLab(SupersetTestCase):
     def test_execute_sql_statements_no_results_backend(
         self, mock_execute_sql_statement, mock_get_query
     ):
-        sql = """
+        sql = dedent(
+            """
             -- comment
             SET @value = 42;
-            SELECT @value AS foo;
-            -- comment
+            SELECT /*+ hint */ @value AS foo;
         """
+        )
         mock_session = mock.MagicMock()
         mock_query = mock.MagicMock()
         mock_query.database.allow_run_async = True
@@ -681,12 +684,13 @@ class TestSqlLab(SupersetTestCase):
     def test_execute_sql_statements_ctas(
         self, mock_execute_sql_statement, mock_get_query
     ):
-        sql = """
+        sql = dedent(
+            """
             -- comment
             SET @value = 42;
-            SELECT @value AS foo;
-            -- comment
+            SELECT /*+ hint */ @value AS foo;
         """
+        )
         mock_session = mock.MagicMock()
         mock_query = mock.MagicMock()
         mock_query.database.allow_run_async = False
@@ -714,7 +718,7 @@ class TestSqlLab(SupersetTestCase):
         mock_execute_sql_statement.assert_has_calls(
             [
                 mock.call(
-                    "SET @value = 42",
+                    "-- comment\nSET @value = 42",
                     mock_query,
                     mock_session,
                     mock_cursor,
@@ -722,7 +726,7 @@ class TestSqlLab(SupersetTestCase):
                     False,
                 ),
                 mock.call(
-                    "SELECT @value AS foo",
+                    "SELECT /*+ hint */ @value AS foo",
                     mock_query,
                     mock_session,
                     mock_cursor,
@@ -761,12 +765,13 @@ class TestSqlLab(SupersetTestCase):
 
         # try invalid CVAS
         mock_query.ctas_method = CtasMethod.VIEW
-        sql = """
+        sql = dedent(
+            """
             -- comment
             SET @value = 42;
-            SELECT @value AS foo;
-            -- comment
+            SELECT /*+ hint */ @value AS foo;
         """
+        )
         with pytest.raises(SupersetErrorException) as excinfo:
             execute_sql_statements(
                 query_id=1,

Reply via email to