Is it possible to unbind an object from an SQLAlchemy session?
I used to deepcopy
it, but as this seems not to be possible when using association proxies I'm searching for another solution to remove the object from a session to add it to another one.
Expunge removes an object from the Session, sending persistent instances to the detached state, and pending instances to the transient state:
session.expunge(obj1)
UPDATE: A detached object can be attached to the same or another session by using
session2.add(obj1)
or merged
session2.merge(obj1)
With merge(), the given instance is not placed within the session, and can be associated with a different session or detached. merge() is very useful for taking the state of any kind of object structure without regard for its origins or current session associations and placing that state within a session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With