Fix interactive stall when a statement ends with a trailing comment - #515
Open
ClaraOswald076 wants to merge 1 commit into
Open
Fix interactive stall when a statement ends with a trailing comment#515ClaraOswald076 wants to merge 1 commit into
ClaraOswald076 wants to merge 1 commit into
Conversation
… the interactive REPL
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.
Summary
Fixes #496.
In the interactive REPL,
CrashBuffer.is_multiline()decides whether thebuffer stays in multiline mode by checking whether the raw input text ends
with
;. A statement with a trailing comment (select 42; -- foo) ends with-- foo, so the condition kept the buffer in multiline mode forever and thesession stalled: pressing Enter never submitted the statement. The non
interactive path (
crash -c '...') does not go through this buffer, which iswhy it worked fine.
Changes
src/crate/crash/repl.py:is_multilinenow strips comments withsqlparse.format(text, strip_comments=True)before looking for theterminating semicolon. sqlparse is syntax-aware, so a
;or--inside astring literal is untouched.
sqlparseis already a dependency of crash,so no new requirements.
tests/test_repl.py: three newCrashBufferTestcases:test for SQL statement with trailing comment stalls in interactive session #496)
Test evidence
Windows, Python 3.11.9, pytest, sqlparse 0.5.5. Pre-fix full-suite baseline:
66 passed (excluding
test_integration, which needs a CrateDB server).Before (upstream code with the new test applied):
After:
Full suite:
69 passed in 0.60s— no regressions.