From 3cbc83449f408b1a7db34a3894a5382eec1a9f9b Mon Sep 17 00:00:00 2001 From: Luiz Otavio <45200344+luizotavio32@users.noreply.github.com> Date: Thu, 16 Apr 2026 09:19:39 -0300 Subject: [PATCH] fix: add comments to SQL clause validation (#39167) (cherry picked from commit 0b419a07f54f3de1b0bb89a41c9b5b047f928f79) --- superset/sql/parse.py | 2 +- tests/unit_tests/sql/parse_tests.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/superset/sql/parse.py b/superset/sql/parse.py index 314ddb40dd7..20fe7f2b0c8 100644 --- a/superset/sql/parse.py +++ b/superset/sql/parse.py @@ -1557,7 +1557,7 @@ def sanitize_clause(clause: str, engine: str) -> str: return Dialect.get_or_raise(dialect).generate( statement._parsed, # pylint: disable=protected-access copy=True, - comments=False, + comments=True, pretty=False, ) except SupersetParseError as ex: diff --git a/tests/unit_tests/sql/parse_tests.py b/tests/unit_tests/sql/parse_tests.py index 274acc01b5a..78b00f4487d 100644 --- a/tests/unit_tests/sql/parse_tests.py +++ b/tests/unit_tests/sql/parse_tests.py @@ -2693,9 +2693,19 @@ def test_is_valid_cvas(sql: str, engine: str, expected: bool) -> None: ), # Compact format ( "col = 'abc' -- comment", - "col = 'abc'", + "col = 'abc' /* comment */", "base", - ), # Comments removed for compact format + ), # Line comments converted to block comments + ( + "TRUE /* precise_count_distinct=true */", + "TRUE /* precise_count_distinct=true */", + "base", + ), # Block comments preserved + ( + "col > 1 /* hint=value */", + "col > 1 /* hint=value */", + "base", + ), # Block comments preserved ("col = 'col1 = 1) AND (col2 = 2'", "col = 'col1 = 1) AND (col2 = 2'", "base"), ("col = 'select 1; select 2'", "col = 'select 1; select 2'", "base"), ("col = 'abc -- comment'", "col = 'abc -- comment'", "base"),