Skip to content

Commit 11a6b7d

Browse files
committed
Stabilize formatting of invalid WHERE clauses.
1 parent f578d03 commit 11a6b7d

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Bug Fixes
2424
* Fix splitting when using DECLARE ... HANDLER (issue581).
2525
* Fix splitting of statements using CASE ... WHEN (issue580).
2626
* Improve formatting of type casts in parentheses.
27+
* Stabilize formatting of invalid SQL statements.
2728

2829

2930
Release 0.3.1 (Feb 29, 2020)

sqlparse/filters/reindent.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ def _process(self, tlist):
102102

103103
def _process_where(self, tlist):
104104
tidx, token = tlist.token_next_by(m=(T.Keyword, 'WHERE'))
105+
if not token:
106+
return
105107
# issue121, errors in statement fixed??
108+
print(tidx, token, tlist)
106109
tlist.insert_before(tidx, self.nl())
107110

108111
with indent(self):

tests/test_regressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,9 @@ def test_as_in_parentheses_indents():
405405
# did raise NoneType has no attribute is_group in _process_parentheses
406406
formatted = sqlparse.format('(as foo)', reindent=True)
407407
assert formatted == '(as foo)'
408+
409+
410+
def test_format_invalid_where_clause():
411+
# did raise ValueError
412+
formatted = sqlparse.format('where, foo', reindent=True)
413+
assert formatted == 'where, foo'

0 commit comments

Comments
 (0)