-
Notifications
You must be signed in to change notification settings - Fork 438
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
MySQLdb.converters is inconsistent about returning bytes or str in Python 3 #145
Comments
Bump. Running into the same issue upgrading from 1.3.9 to 1.3.10. However, 1.3.9 works.
Original Traceback:
|
Hi, This issue is serious for me because all parameterized queries using tuple parameter doesn't work on python 3.5 & mysqlclient 1.3.10 & both of Windows and UNIX. (1.3.9 works.) sample code import MySQLdb
db = ...
db.query("SELECT * FROM table WHERE value IN %(values)s", {"values": (1,2,3)}) partial traceback
|
@stakemura ditto ! |
I'm very confused. First report said it doesn't work 1.3.9. But another report says it works on 1.3.9, but not 1.3.10???? I can't find any relating changes between 1.3.9 and 1.3.10. |
@methane I had the problem described by @stakemura with version 1.3.10, downgrading to 1.3.9 fixes the problem. |
Please stop using tuple argument. It uses underlying broken API. Use ORM instead. Or build string like "(%s, %s, %s, %s)" by yourself. |
please send pull request to add failing tests which describe your cases. |
MySQLdb's string functions and methods are full of chaos. I find #140 broke it again. I can't find any way in backward compatible way. But I don't have enough love and energy to manage this feature. |
I'm so sorry. I mentioned tuple parameter not list. By the way, Tuple adaption is defined as for psycopg2 . I guess this function is quite useful. But I understood this is not defined on Python DB's API specification unfortunately. As you said, I 'll rewrite queries using tuple adaption on MySQL. |
As #174 turned out to be a duplicate, I'd like to chime in with several observation:
|
sure.
ORM is one workaroud.
It's not security issue.
Both feature using very very very complicated part what I don't want to maintain... |
Downgrade to 1.3.9 worked for me too |
ditto |
FWI, encoding tuple is totally broken from long ago.
So I strongly recommend you to don't use it. If you really need it, try #155. |
Since Connections.encoders is broken by design. Tuple and list is escaped directly in `Connection.literal()`. Removed tuple and list from converters mapping. Fixes #145
I upload 1.3.11c1 including #155 to PyPI. |
I've found myself looking for some help on how to do a correct query and landing here. I'm quite concerned about the security issues mentioned. However, I've found later this in the MySQL documentation:
It looks like it's a safer option as the data are separated from the statement. |
The
MySQLdb.converters
module mostly returns strs in Python 3 (which I think is correct), but it ends up calling into_mysql.string_literal
in some cases, which returns bytes instead. When escaping tuples this can lead to TypeErrors:The text was updated successfully, but these errors were encountered: