Conversation
group_values() only looked at the statement's own tokens, so a VALUES list nested in parentheses (subquery, CTE, JOIN source) was never grouped as sql.Values. reindent then treated each row's items as a plain identifier list and broke lines inside every row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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 #506.
The bug
VALUESrows are laid out one per line at the top level, but as soon as theVALUESlist sits inside parentheses (a derived table, a CTE body, a JOINsource)
reindentbreaks lines inside each row instead:Still reproduces on current
master.Root cause
group_values()is the only grouping step ingroup()that doesn't recurseinto sublists — it only scans the statement's own tokens. A nested
VALUEStherefore never becomes a
sql.Valuesgroup:ReindentFilter._process_values()never runs for it, and the innerIdentifierLists are laid out as ordinary column lists (thetlist.within(sql.Values)check in_process_identifierlist()is false).The fix
Decorate
group_valueswith@recurse(), like the other grouping functions.Nested lists now group exactly like top-level ones, so they get the same
layout (with and without
comma_first):I also compared before/after output for
WITH v AS (VALUES ...),JOIN (VALUES ...) AS v (...),IN (SELECT ... FROM (VALUES ...))andMySQL's
ON DUPLICATE KEY UPDATE a = VALUES(a)— the first three now matchthe top-level layout, the last is unchanged, and
str(parse(s)[0]) == sholds for all of them.
Testing
test_grouping_identifiers: nestedVALUESis asql.Valuesgroup.New
TestFormatReindent::test_values_in_parenthesis(plain andcomma_first).Both fail on
masterand pass with the fix.Full suite: 507 passed, 2 xfailed, 1 xpassed.
ruff check sqlparse/clean.
benchmarks/bench_grouping.pystill reports linear on all vectors.ran the tests (
pytest)all style issues addressed (
ruff)your changes are covered by tests
your changes are documented, if needed (CHANGELOG)
🤖 Generated with Claude Code