Skip to content

Commit 31830af

Browse files
committed
Fix andialbrecht#284 as grouping
1 parent e29fbf0 commit 31830af

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

sqlparse/engine/grouping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def valid_prev(token):
121121

122122
def valid_next(token):
123123
ttypes = T.DML, T.DDL
124-
return not imt(token, t=ttypes)
124+
return not imt(token, t=ttypes) and token is not None
125125

126126
def post(tlist, pidx, tidx, nidx):
127127
return pidx, nidx

tests/test_regressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,9 @@ def test_token_next_doesnt_ignore_skip_cm():
314314
sql = '--comment\nselect 1'
315315
tok = sqlparse.parse(sql)[0].token_next(-1, skip_cm=True)[1]
316316
assert tok.value == 'select'
317+
318+
319+
def test_issue284_as_grouping():
320+
sql = 'SELECT x AS'
321+
p = sqlparse.parse(sql)[0]
322+
assert sql == str(p)

0 commit comments

Comments
 (0)