Skip to content

Add support for converting pyformat SQL to positional markers with bulk_parameters#812

Merged
bgunebakan merged 6 commits into
mainfrom
fix/bulk-parameters-pyformat-conversion
Jun 16, 2026
Merged

Add support for converting pyformat SQL to positional markers with bulk_parameters#812
bgunebakan merged 6 commits into
mainfrom
fix/bulk-parameters-pyformat-conversion

Conversation

@bgunebakan

@bgunebakan bgunebakan commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary of the changes / Why this is an improvement

Fixes a silent runtime error when cursor.execute() is called with bulk_parameters and a SQL statement that uses %(name)s (pyformat) placeholders.

When bulk_parameters is passed alongside pyformat SQL, the driver was sending the raw %(name)s markers verbatim to CrateDB, which rejected them with:

SQLParseException[no viable alternative at input 'VALUES (%']

The fix adds an elif branch in execute() that rewrites the SQL template to $N positional markers before the request is sent.

The bug was introduced indirectly by PR #810 which declared paramstyle = "pyformat" for the driver. Before that change, SQLAlchemy generated ? style SQL, so the bulk_parameters path was never fed pyformat placeholders so the broken code path simply didn't exist.

It fixes implementation in sqlalchemy-crate package crate/sqlalchemy-cratedb#266

Checklist

  • Link to issue this PR refers to (if applicable): Fixes #???
  • Unit tests added

@bgunebakan bgunebakan self-assigned this Jun 10, 2026
Comment thread src/crate/client/cursor.py Outdated
@bgunebakan bgunebakan added the bug label Jun 10, 2026
@bgunebakan bgunebakan requested a review from mfussenegger June 12, 2026 09:56
Comment thread docs/by-example/cursor.rst Outdated
Comment thread docs/by-example/cursor.rst Outdated
Comment thread docs/by-example/cursor.rst
Comment thread docs/query.rst Outdated
Comment thread docs/query.rst Outdated
Comment thread docs/query.rst Outdated
Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Comment thread docs/by-example/cursor.rst
Co-authored-by: Bilal Tonga <bilaltonga@gmail.com>
@bgunebakan bgunebakan requested a review from mfussenegger June 15, 2026 11:23
@bgunebakan bgunebakan merged commit a20cf88 into main Jun 16, 2026
23 of 24 checks passed
@bgunebakan bgunebakan deleted the fix/bulk-parameters-pyformat-conversion branch June 16, 2026 07:53
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.

2 participants