Patches item #2866300, was opened at 2009-09-25 14:08
Message generated for change (Comment added) made by gkassel
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=2866300&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Geoff Kassel (gkassel)
Assigned to: Oleg Broytmann (phd)
Summary: ConnectionHub.__get__ TypeError and patch
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Geoff Kassel (gkassel)
Date: 2009-09-27 13:45
Message:
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__')'"?
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2009-09-26 00:02
Message:
I cannot get how 'obj' can be None there. Can you provide a short test
program that demonstrates the problem?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=2866300&group_id=74338
|