object_session() raises instead of returning None for objects not in a session
from sqlalchemy.orm import object_session object_session(object()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "sqlalchemy/orm/session.py", line 1614, in object_session return _state_session(attributes.instance_state(instance)) AttributeError: 'object' object has no attribute '_sa_instance_state'
Comments (5)
-
Account Deleted -
Account Deleted I'm another sqla user, but just my 2 cents is that this is behaving how I would expect it to. If you pass an object that isn't even a sqla object, I would hope for an exception.
If you want to catch that exception and pass on it, then you have the flexibility.
-
Account Deleted The docstring promises that it returns None if the object is not associated, though.
-
repo owner - changed milestone to 0.6.4
- changed component to documentation
- changed status to resolved
the docstring assumes the object is mapped. this inaccuracy is fixed as well as the correct exception in 61562e58435efddda19d15c61afd6e5326745a31
-
repo owner - removed milestone
Removing milestone: 0.6.4 (automated comment)
- Log in to comment
Sorry, that should be: