Formula for determining Transient, Pending, Persistent, Detached

489 views
Skip to first unread message

Kent

unread,
Sep 1, 2010, 11:30:19 AM9/1/10
to sqlalchemy
Please correct me if I'm mistaken and let me know if there is a better
way:

if attributes.instance_state(instance).has_identity:
instance is Persistent or Detached

if attributes.instance_state(instance).session_id:
instance is Pending or Persistent


Thanks,
Kent

Kent

unread,
Sep 1, 2010, 11:33:13 AM9/1/10
to sqlalchemy
I suppose "attributes.instance_state(instance).session_id is not None"
is more correct than "attributes.instance_state(instance).session_id"

Michael Bayer

unread,
Sep 1, 2010, 11:55:45 AM9/1/10
to sqlal...@googlegroups.com

from sqlalchemy.orm import object_session
from sqlalchemy.orm.util import has_identity

transient:

object_session(obj) is None and not has_identity(obj)

detached:

object_session(obj) is None and has_identity(obj)

pending, persistent etc.

You've basically figured out the less public ways of doing the same thing.

Reply all
Reply to author
Forward
0 new messages