Fix trailing SQL comments breaking multiline submit and execution#1559
Open
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
Open
Fix trailing SQL comments breaking multiline submit and execution#1559DiegoDAF wants to merge 1 commit intodbcli:mainfrom
DiegoDAF wants to merge 1 commit intodbcli:mainfrom
Conversation
Two bugs when a comment follows the semicolon (e.g. "SELECT 1; -- note"):
1. pgbuffer._is_complete() checked sql.endswith(";") which returned False
when a comment followed, preventing multiline mode from ever submitting
2. pgexecute.run() used rstrip(";") which couldn't find the semicolon
past the trailing comment, sending malformed SQL to PostgreSQL
Both fixes strip comments (via sqlparse) before checking for the semicolon.
Made with ❤️ and 🤖 Claude
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 two related bugs when a SQL comment follows the semicolon, e.g.:
Bug 1 —
pgbuffer._is_complete():sql.endswith(";")returnedFalsewhen a trailing comment followed the semicolon. In multiline mode, pressing Enter never submitted the query — the UI appeared frozen.Bug 2 —
pgexecute.run():sql.rstrip(";")couldn't strip the semicolon because the string ended with the comment text, not;. The malformed SQL (with embedded;) was sent to PostgreSQL via psycopg's extended query protocol, which doesn't support multiple statements.Fix
Both locations now use
sqlparse.format(sql, strip_comments=True)before checking for / removing the trailing semicolon.Files Changed
pgcli/pgbuffer.py—_is_complete()strips comments beforeendswith(";")pgcli/pgexecute.py—run()strips comments beforerstrip(";")changelog.rst— Added bug fix entry to Upcomingtests/test_trailing_comments.py— 12 new tests covering edge casesTest plan
pytest tests/test_trailing_comments.py -v)vacuum freeze verbose tpd.file_delivery; -- 82% towards emergencyexecutes correctly