Repository navigation
Read a # comment with no space after it as a comment - #2481
Merged
Merged
Conversation
rolandwalker
approved these changes
Nov 29, 2026
rolandwalker
left a comment
Contributor
There was a problem hiding this comment.
Great! Too bad we can't upstream a fix, since sqlparse recently stopped development.
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.
Description
Fixes #2480
MySQL reads
#followed by anything as a comment to the end of the line. sqlparse only does this when a space follows the#. So#drop table t; drop table u;was cut at the;, the commented-outdrop table uwas sent to the server, and#notebefore aDELETEhid it from the destructive warning.The change is one new module,
mycli/packages/utils/sqlparse_utils.py.use_mysql_hash_comments()swaps three patterns on the shared sqlparse lexer:(--|# )...becomes(--|#)...\w[$#\w]*becomes\w[$\w]*[+/@#%^&|^-]+becomes[+/@%^&|^-]+The last two stop a
#from running on into a name or an operator, soa#c;dand1/#c;dread as a comment too.delimiter_command.py,batch_utils.pyandsql_utils.pycall it when they load, next to theMAX_GROUPING_DEPTHlines that already change sqlparse for the whole process.This is a change to sqlparse's shared lexer inside mycli, so I want to say it plainly. Only mycli's own code uses sqlparse in this process, and all of mycli's SQL is MySQL. sqlparse has an open request for this (andialbrecht/sqlparse#512), but a fix in mycli does not wait for a sqlparse release. The patterns are matched by their exact text in sqlparse 0.6.1. If a sqlparse upgrade changes one of them, a new test fails, so the fix cannot stop working without anyone noticing.
What changes for a user:
mycli --batch,/source,-eand stdin keep#comment;with semicoloninside one statement. Real schema files such as urlooker'ssql/schema.sqlwent from 23 statements to 9, with no comment-only statements.is_destructive(),need_completion_refresh()andneed_completion_reset()see the statement after a#noteline./* */comments that contain#are unchanged.;after#wordon asystem,pagerorteeline no longer ends the statement, for examplesystem echo a#b; echo c. That line is one statement now, as it is when the#has a space after it.#comment, as it already does for--and#. This is not changed here. A--batchfile never has a lone CR, because Python reads it as a newline.Tests: new cases in
test_delimitercommand.py,test_batch_utils.pyandtest_sql_utils.pyfail on main (10 failed, 258 passed in those three files) and pass with the fix (268 passed). The full suite is 101 failed, 3492 passed, 133 skipped, 7 xfailed on Windows with the change, and 101 failed, 3475 passed on main. The failing set is the same (no polars or llm package, no pty orpwd).I also compared the splitter with the sqlglot MySQL tokenizer on 24000 random inputs from two generators. 16407 could be compared. The change fixes 1833 wrong splits from main and adds 2. One added case has
#>, where sqlglot reads an operator but MySQL starts a comment, so the change is right there. The other has a--with no space after it, which this change does not touch. With a lone CR in the inputs (24000 inputs) the change fixes 1681 wrong splits and adds 27, and 24 of those have a lone CR.Validated with Claude Opus 5.5.
Checklist
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).