Skip to content

Commit 0fe6e3b

Browse files
committed
Deal with long function params
1 parent fb52a01 commit 0fe6e3b

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

sqlparse/filters/reindent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def _process_identifierlist(self, tlist):
167167

168168
end_at = self.offset + sum(len(i.value) + 1 for i in identifiers)
169169
adjusted_offset = 0
170-
if end_at > (self.wrap_after - self.offset) and self._last_func:
170+
if (self.wrap_after > 0
171+
and end_at > (self.wrap_after - self.offset)
172+
and self._last_func):
171173
adjusted_offset = -len(self._last_func.value) - 1
172174

173175
with offset(self, adjusted_offset), indent(self):
@@ -177,7 +179,8 @@ def _process_identifierlist(self, tlist):
177179
for token in identifiers:
178180
# Add 1 for the "," separator
179181
position += len(token.value) + 1
180-
if position > (self.wrap_after - self.offset):
182+
if (self.wrap_after > 0
183+
and position > (self.wrap_after - self.offset)):
181184
adjust = 0
182185
tlist.insert_before(token, self.nl(offset=adjust))
183186
position = 0

tests/test_format.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ def test_identifier_list_with_functions(self):
453453
" col3",
454454
"from my_table"])
455455

456+
def test_long_identifier_list_with_functions(self):
457+
f = lambda sql: sqlparse.format(sql, reindent=True, wrap_after=30)
458+
s = ("select 'abc' as foo, json_build_object('a', a,"
459+
"'b', b, 'c', c, 'd', d, 'e', e) as col2"
460+
"col3 from my_table")
461+
assert f(s) == '\n'.join([
462+
"select 'abc' as foo,",
463+
" json_build_object('a',",
464+
" a, 'b', b, 'c', c, 'd', d,",
465+
" 'e', e) as col2col3",
466+
"from my_table"])
467+
456468
def test_case(self):
457469
f = lambda sql: sqlparse.format(sql, reindent=True)
458470
s = 'case when foo = 1 then 2 when foo = 3 then 4 else 5 end'

0 commit comments

Comments
 (0)