Repository navigation
fix: send queries without parameters without driver formatting - #1794
Open
ahmedpdf445-stack wants to merge 1 commit into
Open
ahmedpdf445-stack wants to merge 1 commit into
ahmedpdf445-stack wants to merge 1 commit into
Conversation
A comment that holds a literal % fails to declare: Connection.query always formats the statement with its arguments, even when there are none, so the sign is read as a placeholder (MySQL: not enough arguments for format string, PostgreSQL: tuple index out of range). Doubling it in quote_comment stores the comment as declared, and %% is then stored as written instead of collapsing to %. This is the escape _comment_literal in migrate.py already applies.
ahmedpdf445-stack
force-pushed
the
fix/literal-percent-in-comments
branch
from
December 5, 2026 09:41
a8213a6 to
0aca8bb
Compare
This branch has not been deployed
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.
Fixes #1789
The bug
A table or attribute comment that holds a literal
%fails to declare, on both backends:ProgrammingError: not enough arguments for format stringIndexError: tuple index out of rangeConnection.queryalways formats the statement with its arguments, even when there are none, so the%in the comment is read as a placeholder. Writing%%works around it today, but the comment is then stored with a single%.The fix
quote_commentdoubles a percent sign, the escape_comment_literalinmigrate.pyalready applies to comments. The formatted statement then holds the comment as declared, on both adapters, for column comments, table comments and the ALTER statements that quote comments. A comment written as%%is now stored as%%instead of%.I first tried sending the statement to the cursor without parameters. That fixes the comments, but it breaks the places that build
%%for LIKE patterns (condition.py,dependencies.py) and the tests that pin them, so the escape stays where the rest of the code base keeps it.Tests
tests/unit/test_comment_percent.py, no database needed:test_mysql_comment_keeps_the_percentandtest_postgres_comment_keeps_the_percentformat the quoted comment the way the driver does and assert it reads back as declared, for50%,100%%,50%alone and%alone. They fail before the change.test_mysql_create_table_sql_keeps_the_percentcovers the column and table comment of a created table.pytest tests/unit1925 passed,ruff checkclean.