Repository navigation
Conversation
AlignedIndentFilter._process_case appends a pseudo-case for the END token
so it can align it, then uses that case's first token as the insert
anchor. token_next_by() returns (None, None) when the CASE has no END
token of its own - which happens when the END is swallowed by a nested
group - and the filter then called insert_before(None):
>>> sqlparse.format("CASE 'a' := WHERE END SELECT GO # ->>",
... reindent_aligned=True)
ValueError: list.index(x): x not in list
Only add the END pseudo-case when an END token was actually found.
Alignment of well-formed CASE constructs is unchanged.
Closes andialbrecht#886
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #886.
AlignedIndentFilter._process_caseappends a pseudo-case holding theENDtoken so it can align it too, then uses that case's first token as the insert anchor:token_next_by()returns(None, None)when theCasegroup has noENDtoken of its own. That happens when theENDis swallowed by a nested group:value[0]is thenNone, andinsert_before(None)fails insidetoken_index().Change
sqlparse/filters/aligned_indent.py: only append the END pseudo-case when anENDtoken was actually found. There is nothing to align otherwise, so skipping it is correct rather than merely non-crashing.Behaviour
Reported input now formats to itself instead of raising. Well-formed
CASEalignment is untouched:Tests
test_issue886_reindent_aligned_malformed_caseintests/test_regressions.py.A
CHANGELOGentry is added underDevelopment Version.