-
Notifications
You must be signed in to change notification settings - Fork 717
Open
Description
Describe the bug
When using
result = sqlparse.format(
sql=sql_text, strip_comments=True, keyword_case="upper", reindent=True
)
On this SQL issue.sql we still have tabulations in format of "\t" and not spaces + we have comments that stay and aren't stripped
To Reproduce
Steps to reproduce the behavior.
Use this script
import sqlparse
def strip_sql_comments(sql_text: str, reindent=False) -> str:
"""
Strip comments from SQL.
Args:
sql_text (str): unformatted SQL.
Returns:
str: formatted SQL.
"""
result = sqlparse.format(
sql=sql_text, strip_comments=True, keyword_case="upper", reindent=reindent
)
return result
sql_path="issue.sql"
with open(sql_path, "r", encoding="utf-8") as file:
sql_content = file.read()
# Run the function
cleaned_sql = strip_sql_comments(sql_content, reindent=True)
print(cleaned_sql)
What's the concrete error:
No error/traceback occurs; the function runs successfully but does not strip the comments or normalize tabs as expected.
Expected behavior
All -- comments should be fully removed when strip_comments=True. Tabs should be converted to spaces during reindentation for consistent indentation.
Versions (please complete the following information):
- Python 3.12.0
- sqlparse 0.5.3
Metadata
Metadata
Assignees
Labels
No labels