Re: [SQLObject] boolean types & python 2.2.x
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2003-12-15 17:52:15
|
On Dec 6, 2003, at 3:55 PM, Greg Brown wrote: > I've found a minor problem using boolean columns on Pythons that don't > have a builtin boolean type: > > File "SQLObject/DBConnection.py", line 72, in _runWithConnection > val = meth(conn, *args) > File "SQLObject/DBConnection.py", line 457, in _queryInsertID > q = self._insertSQL(table, names, values) > File "SQLObject/DBConnection.py", line 154, in _insertSQL > ', '.join([self.sqlrepr(v) for v in values]))) > File "SQLObject/DBConnection.py", line 365, in sqlrepr > return sqlrepr(v, self.dbName) > File "SQLObject/Converters.py", line 168, in sqlrepr > raise ValueError, "Unknown SQL builtin type: %s for %s" % \ > ValueError: Unknown SQL builtin type: <type 'instance'> for TRUE > > For Python 2.2, a BOOL class is being defined to simulate the > important behavior of 2.3's builtin 'bool' type. The problem has to > do with how the BOOL is being added to the ConverterRegistry. It's > being registered as: > > registerConverter(type(TRUE), BoolConverter) > > ...which is how the rest of the converters are being registered in > Converters.py. This doesn't work because all the others are new-style > classes that can be discriminated by type(x) while BOOL is an > old-style class, and the type() of all old-style classes is > 'instance'. Old-style classes are being correctly registered with the > ConverterRegistry in SQLBuilder.py, with only the Class object being > passed into registerConverter() instead of the type() of the class. > > It seems like the cleanest fix is to make BOOL a new-style class by > changing it's definition to: > > class BOOL(object): > > so that it can be registered in the same way as all other types in the > Converters.py module regardless of whether it's on Python 2.2 or 2.3. > > This is with SQLObject 0.5.1, by the way. Yes, it sounds like it's an oversight, and I couldn't test it because I don't have any version of Python 2.2 where True and False aren't their own objects. -- Ian Bicking | ia...@co... | http://blog.ianbicking.org |