Skip to content

Commit

Permalink
fix: handle comments in has_table_query (#23882)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored and eschutho committed Jun 6, 2023
1 parent e7e1bdc commit 57fd6d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit_tests/sql_parse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 57fd6d4

Please sign in to comment.