This is an automated email from the ASF dual-hosted git repository.
johnbodley 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 5ed48760fb chore(sqllab): Do not strip comments when executing SQL
statements (#27725)
5ed48760fb is described below
commit 5ed48760fbcc0f5966b42aadd579eb2ab65f8631
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/sqllab_tests.py | 37 +++++++++++++++++++--------------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 3fa80fbc45..e34f7e2fde 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -419,7 +419,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/sqllab_tests.py
b/tests/integration_tests/sqllab_tests.py
index 30b8401cc6..5248aab2eb 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
@@ -639,12 +640,13 @@ class TestSqlLab(SupersetTestCase):
mock_get_query,
mock_db,
):
- sql = """
+ sql = dedent(
+ """
-- comment
SET @value = 42;
- SELECT @value AS foo;
- -- comment
+ SELECT /*+ hint */ @value AS foo;
"""
+ )
mock_db = mock.MagicMock()
mock_query = mock.MagicMock()
mock_query.database.allow_run_async = False
@@ -667,14 +669,14 @@ class TestSqlLab(SupersetTestCase):
mock_execute_sql_statement.assert_has_calls(
[
mock.call(
- "SET @value = 42",
+ "-- comment\nSET @value = 42",
mock_query,
mock_cursor,
None,
False,
),
mock.call(
- "SELECT @value AS foo",
+ "SELECT /*+ hint */ @value AS foo",
mock_query,
mock_cursor,
None,
@@ -689,12 +691,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_query = mock.MagicMock()
mock_query.database.allow_run_async = True
mock_cursor = mock.MagicMock()
@@ -741,12 +744,13 @@ class TestSqlLab(SupersetTestCase):
mock_get_query,
mock_db,
):
- sql = """
+ sql = dedent(
+ """
-- comment
SET @value = 42;
- SELECT @value AS foo;
- -- comment
+ SELECT /*+ hint */ @value AS foo;
"""
+ )
mock_db = mock.MagicMock()
mock_query = mock.MagicMock()
mock_query.database.allow_run_async = False
@@ -773,14 +777,14 @@ class TestSqlLab(SupersetTestCase):
mock_execute_sql_statement.assert_has_calls(
[
mock.call(
- "SET @value = 42",
+ "-- comment\nSET @value = 42",
mock_query,
mock_cursor,
None,
False,
),
mock.call(
- "SELECT @value AS foo",
+ "SELECT /*+ hint */ @value AS foo",
mock_query,
mock_cursor,
None,
@@ -817,12 +821,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,