object_session can sometimes generate TypeError (patch included)

Issue #940 resolved
Former user created an issue

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)

  1. Log in to comment