Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ def group_tokens(self, grp_cls, start, end,
grp = start
grp.tokens.extend(subtokens)
del self.tokens[start_idx + 1:end_idx]
grp.value = str(start)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale group value breaks wrapping

Medium Severity

Removing the grp.value refresh in the extend=True path makes TokenList.value stay at its construction-time cache even when the group grows. Some formatting logic relies on len(token.value) for grouped tokens (e.g., identifiers) to decide wrapping/indentation, so extended groups can be measured too short and produce different (potentially overlong) formatted output.

Fix in Cursor Fix in Web

else:
subtokens = self.tokens[start_idx:end_idx]
grp = grp_cls(subtokens)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def test_configurable_keywords():
tokens = sqlparse.parse(sql)[0]

assert list(
(t.ttype, t.value) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
(t.ttype, str(t)) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
) == [
(sqlparse.tokens.Keyword.DML, "select"),
(sqlparse.tokens.Wildcard, "*"),
Expand All @@ -569,7 +569,7 @@ def test_configurable_keywords():
Lexer.get_default_instance().default_initialization()

assert list(
(t.ttype, t.value) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
(t.ttype, str(t)) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
) == [
(sqlparse.tokens.Keyword.DML, "select"),
(sqlparse.tokens.Wildcard, "*"),
Expand Down
Loading