Hi,
Found a TypeError raised from ConnectionHub.__get__ that seems to happen when overriding the SQLObject.__init__ method.
Here's the associated trace:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/lvm/var/www/localhost/webapp/product/product/model/dbfile.py", line 220, in __init__
SQLObject.__init__(self, contentType = contentType, _data = data)
File "//usr/lib/python2.5/site-packages/sqlobject/main.py", line 1223, in __init__
self._create(id, **kw)
File "//usr/lib/python2.5/site-packages/sqlobject/main.py", line 1271, in _create
self._SO_finishCreate(id)
File "//usr/lib/python2.5/site-packages/sqlobject/main.py", line 1294, in _SO_finishCreate
id = self._connection.queryInsertID(self,
File "//usr/lib/python2.5/site-packages/turbogears/database.py", line 273, in __get__
return self.hub.__get__(obj, type)
File "/usr/lib/python2.5/site-packages/sqlobject/dbconnection.py", line 826, in __get__
if obj and obj.__dict__.has_key('_connection'):
TypeError: an integer is required
The object 'obj' in question is an uninitialized SQLObject (an object of a database-backed file class named DBFile), and the error is raised from the 'if obj' condition.
I've fixed this with the attached patch.
Unified diff patch for dbconnection.py from SQLObject 0.11.0
I cannot get how 'obj' can be None there. Can you provide a short test program that demonstrates the problem?
The point of the 'obj is not None' condition (and I believe the original 'if obj') is to ensure that there is a valid object to extract the attribute __dict__ from. All I've done here is changed the test from one that Python seems to want an Integer-coercible value for - which seems to fail with uninitialized SQLObjects - to one that makes a little more explicit the requirement that the object is one that can have attributes extracted from it.
I haven't actually come across a case where this object is None, so I don't think I can come up with a test program that demonstrates this. I presume the original intent of the code is something like insurance against an AttributeError during object destruction.
On second thought, perhaps a better condition would be "if hasattr(obj, '__dict__')'"?
Now I see. 'obj' there can be either None for SQLObject classes (TestClass._connection) or an instance for SQLObject instances (test_instance._connection). For an SQLObject class whose instances can be coerced to boolean False the test 'if obj' fails where it must succeed. I fixed that by testing 'if (obj is not None)'; there is no need to do hasattr - if obj is not None it must be an SQLObject instance, and they always have __dict__.
Committed in the revisions 4001-4003 (branches 0.10, 0.11 and the trunk). Will be in the next round of releases. Thank you!