Skip to content

sqlparse.format does not strip -- comments and fails to convert tabs to spaces when reindent=True #10

Description

@kkipngenokoech

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

Mirrored from andialbrecht/sqlparse#823 for Phoenix evaluation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai:failedPhoenix AI: run failed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions