Skip to content

Add support for executemany()#810

Merged
bgunebakan merged 2 commits into
mainfrom
fix/807-executemany-does-not-translate-pyformat-dict-params
Jun 9, 2026
Merged

Add support for executemany()#810
bgunebakan merged 2 commits into
mainfrom
fix/807-executemany-does-not-translate-pyformat-dict-params

Conversation

@bgunebakan

Copy link
Copy Markdown
Contributor

Summary of the changes / Why this is an improvement

Checklist

@bgunebakan bgunebakan added the bug label Jun 8, 2026
@bgunebakan bgunebakan linked an issue Jun 8, 2026 that may be closed by this pull request
@bgunebakan bgunebakan force-pushed the fix/807-executemany-does-not-translate-pyformat-dict-params branch from e6aed17 to 91299e4 Compare June 8, 2026 12:21
@bgunebakan bgunebakan requested review from kneth and mfussenegger June 8, 2026 12:24

@kneth kneth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +155 to +156
and isinstance(bulk_parameters[0], dict)
and _NAMED_PARAM_RE.search(sql)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is a mix of dict/non-dict args?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently we raise an error. Do we have case to use mix of dict/non-dict together? I couldn't find how server handle that. What it should do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising an error sounds good if it's one that makes it clear that mixing dict/non-dict together isn't supported.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added edge case here cursor.py:92 so it will raise ProgrammingError and added test for that.

):
cursor = mocked_connection.cursor()
cursor.executemany(
"INSERT INTO characters (name, age) VALUES (%(name)s, %(age)s)",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a case where one named argument is used multiple times and check that it gets the same position number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests 10faeae

@bgunebakan bgunebakan merged commit 17656c3 into main Jun 9, 2026
24 of 25 checks passed
@bgunebakan bgunebakan deleted the fix/807-executemany-does-not-translate-pyformat-dict-params branch June 9, 2026 08:28
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.

executemany() does not translate pyformat dict params

3 participants