diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2020-09-30 15:39:54 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2020-09-30 15:39:54 +0200 |
| commit | 11a6b7db8b19bf1f92754a6272839c66ee630683 (patch) | |
| tree | db5eb66f317d2c3ecf34643b46328a65343813e2 | |
| parent | f578d03ef7a0d1b0f84c59c4699ee307e725fc9c (diff) | |
| download | sqlparse-11a6b7db8b19bf1f92754a6272839c66ee630683.tar.gz | |
Stabilize formatting of invalid WHERE clauses.
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | sqlparse/filters/reindent.py | 3 | ||||
| -rw-r--r-- | tests/test_regressions.py | 6 |
3 files changed, 10 insertions, 0 deletions
@@ -24,6 +24,7 @@ Bug Fixes * Fix splitting when using DECLARE ... HANDLER (issue581). * Fix splitting of statements using CASE ... WHEN (issue580). * Improve formatting of type casts in parentheses. +* Stabilize formatting of invalid SQL statements. Release 0.3.1 (Feb 29, 2020) diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py index 2d68abb..ced9f83 100644 --- a/sqlparse/filters/reindent.py +++ b/sqlparse/filters/reindent.py @@ -102,7 +102,10 @@ class ReindentFilter: def _process_where(self, tlist): tidx, token = tlist.token_next_by(m=(T.Keyword, 'WHERE')) + if not token: + return # issue121, errors in statement fixed?? + print(tidx, token, tlist) tlist.insert_before(tidx, self.nl()) with indent(self): diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 13c752b..b247ce2 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -405,3 +405,9 @@ def test_as_in_parentheses_indents(): # did raise NoneType has no attribute is_group in _process_parentheses formatted = sqlparse.format('(as foo)', reindent=True) assert formatted == '(as foo)' + + +def test_format_invalid_where_clause(): + # did raise ValueError + formatted = sqlparse.format('where, foo', reindent=True) + assert formatted == 'where, foo' |
