Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
chore(sqllab): Do not strip comments when executing SQL statements (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed Apr 4, 2024
1 parent 601432a commit 5ed4876
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 21 additions & 16 deletions tests/integration_tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -639,12 +640,13 @@ def test_execute_sql_statements(
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
Expand All @@ -667,14 +669,14 @@ def test_execute_sql_statements(
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,
Expand All @@ -689,12 +691,13 @@ def test_execute_sql_statements(
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()
Expand Down Expand Up @@ -741,12 +744,13 @@ def test_execute_sql_statements_ctas(
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
Expand All @@ -773,14 +777,14 @@ def test_execute_sql_statements_ctas(
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,
Expand Down Expand Up @@ -817,12 +821,13 @@ def test_execute_sql_statements_ctas(

# 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,
Expand Down

0 comments on commit 5ed4876

Please sign in to comment.