- changed status to resolved
object_session can sometimes generate TypeError (patch included)
Issue #940
resolved
sqlalchelmy.orm.session.object_session function can sometimes generate TypeError exceptions, when session is garbage collected while some objects that were in that session exist (have _sa_session_id set) and there is lazy attribute load attempt on their attributes:
File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\attributes.py", line 44, in __get__
return self.impl.get(instance._state)
File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\attributes.py", line 223, in get
value = callable_()
File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\strategies.py", line 436, in __call__
session = sessionlib.object_session(instance)
File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\session.py", line 1144, in object_session
if instance in sess:
exceptions.TypeError: argument of type 'NoneType' is not iterable
Attached simple patch adds "sess is not None" do this function, fixing the problem (in this particular case, result being sqlalchemy.exceptions.InvalidRequestError raised correctly).
Comments (1)
-
repo owner - Log in to comment
thank you, 6d486fb2e77e338ac4d45ff5ed45561abb5c81b3.