Skip to content

Fix end unconditionally decrementing the split level, but case not incrementing it in a plain select#839

Open
lorenzhs wants to merge 1 commit intoandialbrecht:masterfrom
lorenzhs:fix/end-level
Open

Fix end unconditionally decrementing the split level, but case not incrementing it in a plain select#839
lorenzhs wants to merge 1 commit intoandialbrecht:masterfrom
lorenzhs:fix/end-level

Conversation

@lorenzhs
Copy link

Fixes inconsistent level handling of CASE ... END:

  • CASE only sets the _in_case flag and returns a +1 level diff if it's in a CREATE statement
  • the matching END unconditionally decreases the level

This led to the level being one lower than it should have been after the CASE WHEN ... END block.

The way this caused trouble was in splitting: combined with some escaping trouble (#838) this led to a query incorrectly being split into two.

Checklist:

  • ran the tests (pytest)
  • all style issues addressed (flake8)
  • your changes are covered by tests
  • your changes are documented, if needed

lorenzhs added a commit to firebolt-db/firebolt-python-sdk that referenced this pull request Mar 23, 2026
Replace git dependency on lorenzhs/sqlparse fork with a monkey-patch of
StatementSplitter._change_splitlevel in statement_formatter.py.

The upstream sqlparse project isn't very active and the fix for CASE...END level
tracking (andialbrecht/sqlparse#839) was not yet
released.  PyPI rejects packages with VCS dependencies, so vendoring the fix
inline unblocks publishing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant