You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2023/06/14 15:52:01 UTC

[superset] 11/18: fix: handle comments in `has_table_query` (#23882)

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

elizabeth pushed a commit to tag 2.1.1rc1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 9e6c9d2aa3e66a157c41e270d66da3b84165630e
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Mon May 1 11:06:54 2023 -0700

    fix: handle comments in `has_table_query` (#23882)
---
 superset/sql_parse.py               | 4 +++-
 tests/unit_tests/sql_parse_tests.py | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index ab2f044172..a3c1af87b0 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -509,6 +509,9 @@ def has_table_query(token_list: TokenList) -> bool:
     """
     state = InsertRLSState.SCANNING
     for token in token_list.tokens:
+        # Ignore comments
+        if isinstance(token, sqlparse.sql.Comment):
+            continue
 
         # Recurse into child token list
         if isinstance(token, TokenList) and has_table_query(token):
@@ -607,7 +610,6 @@ def insert_rls(
     rls: Optional[TokenList] = None
     state = InsertRLSState.SCANNING
     for token in token_list.tokens:
-
         # Recurse into child token list
         if isinstance(token, TokenList):
             i = token_list.tokens.index(token)
diff --git a/tests/unit_tests/sql_parse_tests.py b/tests/unit_tests/sql_parse_tests.py
index ba3da69aae..d6939fa080 100644
--- a/tests/unit_tests/sql_parse_tests.py
+++ b/tests/unit_tests/sql_parse_tests.py
@@ -1195,6 +1195,14 @@ def test_sqlparse_issue_652():
         ("extract(HOUR from from_unixtime(hour_ts)", False),
         ("(SELECT * FROM table)", True),
         ("(SELECT COUNT(DISTINCT name) from birth_names)", True),
+        (
+            "(SELECT table_name FROM information_schema.tables WHERE table_name LIKE '%user%' LIMIT 1)",
+            True,
+        ),
+        (
+            "(SELECT table_name FROM /**/ information_schema.tables WHERE table_name LIKE '%user%' LIMIT 1)",
+            True,
+        ),
     ],
 )
 def test_has_table_query(sql: str, expected: bool) -> None: