Conversation
reindent_aligned sets strip_whitespace, so the whitespace that separated one statement from the next is removed before AlignedIndentFilter runs. ReindentFilter.process() compensates by inserting a newline ahead of every statement after the first; AlignedIndentFilter.process() did not, so formatting a file of statements produced "... from a;select * ..." with the second statement starting mid-line. Insert the same separator in AlignedIndentFilter, using the rule ReindentFilter already uses.
adarshsm
marked this pull request as ready for review
September 22, 2026 12:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #673.
The bug
sqlformat -a(format(sql, reindent_aligned=True)) runs consecutivestatements together, so the second statement starts in the middle of the last
line of the first:
Printed:
reindent=Trueon the same input does the right thing:Root cause
reindent_alignedturns onstrip_whitespace(formatter.py), so by the timeAlignedIndentFilterruns, the whitespace that separated one statement fromthe next has already been removed — and
AlignedIndentFilter._process_statementpops any remaining leading whitespace as well.
ReindentFilter.process()already compensates for exactly this, re-inserting anewline before every statement after the first:
AlignedIndentFilter.process()had no such step, so nothing put a separatorback.
The fix
Apply the same separator logic in
AlignedIndentFilter.process(), reusingReindentFilter's rule so the two reindent modes agree. The filter isconstructed per
format()call, so_last_stmtdoesn't leak between calls —same as in
ReindentFilter.After:
Single-statement output is unchanged.
Testing
TestFormatReindentAligned::test_multiple_statements_are_separated;verified it fails on
master(from t1;select bon one line) and passeswith the fix.
ruff check sqlparse/clean.