Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash of cursor.execute() when passing mapping as args in 1.4.0. #323

Closed
felixxm opened this issue Jan 18, 2019 · 4 comments
Closed

Crash of cursor.execute() when passing mapping as args in 1.4.0. #323

felixxm opened this issue Jan 18, 2019 · 4 comments

Comments

@felixxm
Copy link

felixxm commented Jan 18, 2019

In the Django's test suite we encounter issues with mysqliclient==1.4.0. cursor.execute() crashes when passing mapping in args, e.g.

cursor.execute(
    'SELECT * FROM raw_query_author WHERE first_name = %(first)s',
    {'first': 'Bob'},
)

Stacktrace:

MySQLdb/cursors.py", line 188, in execute
    query = query % args
KeyError: b'first'

It is probably related with 5e8eeac.

See test failure.

@felixxm
Copy link
Author

felixxm commented Jan 18, 2019

Encoding keys fixed issue for me:

diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py
index b8c0d88..e612f1a 100644
--- a/MySQLdb/cursors.py
+++ b/MySQLdb/cursors.py
@@ -181,7 +181,7 @@ class BaseCursor(object):
 
         if args is not None:
             if isinstance(args, dict):
-                args = dict((key, db.literal(item)) for key, item in args.items())
+                args = {key.encode(db.encoding): db.literal(item) for key, item in args.items()}
             else:
                 args = tuple(map(db.literal, args))
             try:

@andreymal

This comment has been minimized.

@methane
Copy link
Member

methane commented Jan 19, 2019

(side note: why HISTORY.rst does not contain info about the drop of Python 3.4 support?

Just missed.

It also breaks semver)

I'm not follow semver strictly. Especially, many projects drop old Pyhton support without increasing major version. Django 2.1 dropped Python 3.4 support too.

@felixxm
Copy link
Author

felixxm commented Jan 19, 2019

@methane Many thanks for the new release 🍾 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants