Skip to content

Fix interactive stall when a statement ends with a trailing comment - #515

Open
ClaraOswald076 wants to merge 1 commit into
crate:mainfrom
ClaraOswald076:fix/issue-496
Open

Fix interactive stall when a statement ends with a trailing comment#515
ClaraOswald076 wants to merge 1 commit into
crate:mainfrom
ClaraOswald076:fix/issue-496

Conversation

@ClaraOswald076

Copy link
Copy Markdown

Summary

Fixes #496.

In the interactive REPL, CrashBuffer.is_multiline() decides whether the
buffer 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 the
session stalled: pressing Enter never submitted the statement. The non
interactive path (crash -c '...') does not go through this buffer, which is
why it worked fine.

Changes

  • src/crate/crash/repl.py: is_multiline now strips comments with
    sqlparse.format(text, strip_comments=True) before looking for the
    terminating semicolon. sqlparse is syntax-aware, so a ; or -- inside a
    string literal is untouched. sqlparse is already a dependency of crash,
    so no new requirements.
  • tests/test_repl.py: three new CrashBufferTest cases:

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):

tests/test_repl.py::CrashBufferTest::test_statement_with_trailing_comment_is_not_multiline FAILED
E       AssertionError: True is not false
========================= 1 failed, 2 passed in 0.79s =========================

After:

tests/test_repl.py::CrashBufferTest::test_statement_with_trailing_comment_is_not_multiline PASSED
============================== 4 passed in 0.41s ==============================

Full suite: 69 passed in 0.60s — no regressions.

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.

SQL statement with trailing comment stalls in interactive session

1 participant