MySQL for Python (MySQLdb) – Enum Datatypes Return a Set
Monday, June 11th, 2007This is a bug which appears to have been fixed in the latest MySQLdb release:
SourceForge.net: Detail: 1561190 – enum return list
Also here’s a discussion on it.
If you don’t feel like upgrading MySQLdb or can’t, I made this function to work around the issue. You just run your returned values through it to set them straight. And the good thing is it’s harmless to still run even after you do upgrade and this problem is fixed.
def enum_set_to_str(val):
"""Fixes http://sourceforge.net/tracker/index.php?func=detail&aid=1561190&group_id=22307&atid=374932
enum returns set, until they upgrade. Should always be harmless to run"""
import sets
if type(val) in [sets.Set,set] and len(val)==1:
return list(val)[0]
else:
return val