diff --git a/superset/sql_lab.py b/superset/sql_lab.py index 3fa80fbc45179..e34f7e2fde7d3 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 30b8401cc6f6d..5248aab2eb4de 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 @@ 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 @@ -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, @@ -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() @@ -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 @@ -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, @@ -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,