Using the event hook is likely the most direct way to see where it's happening, 
either via logging or pdb:

https://docs.sqlalchemy.org/en/13/orm/events.html?highlight=persistent_to_detached#sqlalchemy.orm.events.SessionEvents.persistent_to_detached



On Wed, Apr 22, 2020, at 8:57 PM, Jonathan Vanasco wrote:
> I'm trying to figure out how I got a DetatchedInstanceError
> 
> 
> DetachedInstanceError: Parent instance <AcmeAuthorization at 0x107a62b90> is 
> not bound to a Session; lazy load operation of attribute 'domain' cannot 
> proceed (Background on this error at: http://sqlalche.me/e/bhk3)
> 
> This is happening in a web application where I never call 
> `dbSession.close()`. It does use zope.sqlalchemy for pyramid_tm, but 
> `keep_session` is True. I set `expire_on_commit=False` on the sessionmaker.
> 
> Any tips on the best ways to troubleshoot how/where this is getting removed 
> from a session?
> 
> 
> 
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/3e2d1a58-3f95-4021-9e3a-8b20fb9a2559%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/3e2d1a58-3f95-4021-9e3a-8b20fb9a2559%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/16a6c167-0854-494d-b29f-7a925aa1f09b%40www.fastmail.com.

Reply via email to