Skip to content

Fix doubled percent signs with named parameters - #854

Open
florinutz wants to merge 1 commit into
mainfrom
flo/853/percent-escape
Open

florinutz wants to merge 1 commit into
mainfrom
flo/853/percent-escape

Conversation

@florinutz

Copy link
Copy Markdown
Contributor

SQLAlchemy writes a literal percent sign as %% for a driver that takes %(name)s parameters, and the cursor sent %% to crate unchanged (#853). So SELECT 'a%' came back as a%%, and the modulo operator failed to parse.

The cursor now turns %% into % in the same pass that converts %(name)s to $N, as psycopg does. This covers execute() with a dict (an empty one included), executemany() with dict rows, and bulk_parameters with a %(name)s statement. A statement without named parameters is sent as before (psycopg leaves %% alone there too).

I also made executemany() leave the conversion to execute(). Both converted the statement, and on the second pass the text %(a)s left by an escaped %%(a)s would be read as a placeholder.

Closes #853.

executemany() leaves the conversion to execute(), so a statement is converted once.
@florinutz florinutz self-assigned this Nov 26, 2026
@florinutz
florinutz marked this pull request as ready for review November 26, 2026 18:04
@florinutz
florinutz requested a review from bgunebakan November 26, 2026 18:04
@florinutz florinutz added the bug label Nov 26, 2026
@mergify

mergify Bot commented Nov 26, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A percent sign in a statement reaches the server doubled

1 participant