[Python-modules-team] python-mysqldb bug in a select with a Set filed type
Manuel J. Posse (CUCO)
mposse at udc.es
Mon Aug 27 07:56:31 UTC 2007
Helo,
I am using Debian Etch on my System.
I was trying to use Mysql filed Set type over Python, and I have found a little bug in your code.
The bug is in the function Str2Set in the file "site-packages/MySQLdb/converters.py" line 44:
def Str2Set(s):
values = s.split(',')
return apply(str, tuple(values))
Must be something like:
def Str2Set(s):
values = s.split(',')
return map(str, tuple(values)) # if you want a list
return tuple(map(str, tuple(values))) # if you want a tuple
I attach a simple program to see the bug.
The output with your original code:
$ ./python-mysqlbd-bug
Traceback (most recent call last):
File "./python-mysqlbd-bug", line 18, in ?
cursor.execute(query)
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 158, in execute
self.errorhandler(self, TypeError, m)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: str() takes at most 1 argument (2 given)
And with the workarround:
$ ./python-mysqlbd-bug
first ('root', 'zone')
second ('build',)
I was trying to change the conversion using MySQLdb.converters but i can't get it.
import MySQLdb
import MySQLdb.converters
conversions = MySQLdb.converters.conversions.copy()
conversions[MySQLdb.constants.FIELD_TYPE.SET]=my_Str2Set
db=MySQLdb.connect(db="test",read_default_file="~/.my.cnf",conv=conversions)
I do not want to change your code because if I do it, i will loss all your patches to this file ....
I expect that you will publish a patch that solve this problem ...
Thanks,
Cuco.
--
Manuel José Posse Fernández
Técnico Superior en Informática
Universidade da Coruña
Servizo de Informática e Comunicacións
Area de Rede e Comunicacións
Tel: +34-981-167-000/1198
Fax: +34-981-167-172
Email: mposse at udc.es
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-mysqlbd-bug
Type: text/x-python
Size: 577 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/python-modules-team/attachments/20070827/b49526bd/attachment.py
More information about the Python-modules-team
mailing list