Re: [sqlalchemy] Objects wrongly persistent after rollback

2018-08-24 Thread Mike Bayer
Here's a helper function that accommodates for the object being expired: from sqlalchemy.orm import exc from sqlalchemy import inspect def safe_is_persistent(obj): state = inspect(obj) if state.expired: try: state.mapper.primary_key_from_instance(obj) except

Re: [sqlalchemy] Objects wrongly persistent after rollback

2018-08-24 Thread Mike Bayer
On Fri, Aug 24, 2018 at 3:12 AM, Chris Wilson wrote: > Dear Michael, > > > > I have discovered that under very particular circumstances, SQLAlchemy > forgets that an object was newly created in a transaction, and if that > transaction rolls back, the object’s state is not reset from persistent to

[sqlalchemy] Objects wrongly persistent after rollback

2018-08-24 Thread Chris Wilson
Dear Michael, I have discovered that under very particular circumstances, SQLAlchemy forgets that an object was newly created in a transaction, and if that transaction rolls back, the object's state is not reset from persistent to transient. It seems to rely on the following: *Open