Re: [sqlalchemy] debugging DetachedInstanceError

2020-04-23 Thread Jonathan Vanasco


On Thursday, April 23, 2020 at 10:17:12 AM UTC-4, Mike Bayer wrote:
>
> 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
>  
> 
>

 
Awesome! Thanks mike. That's exactly what I needed.

After several hours of debugging, I finally tracked down the issue - which 
solved at least 4 outstanding bugs, and let me clear out a bunch of code.  
And now I can have `expire_on_commit` back too!

I never realized that `zope.sqlalchemy.mark_changed(` has it's own 
`keep_session` kwarg... which defaults to `False` and does not inherit from 
the existing configuration. 

I can't tell why the errors on this was inconsistent.  The app has a 
simplified "commit" hook that lets me handle multiple `pyramid_tm` commits 
in a single request, and I invoke mark_changed() in there to pick up a few 
edge cases.  In a small number of these instances, I lost the 
`keep_session` setting - in others I didn't.  








-- 
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/52dbb2c4-8eb7-4de6-b09b-fb5e7f4320ef%40googlegroups.com.


Re: [sqlalchemy] debugging DetachedInstanceError

2020-04-23 Thread Mike Bayer
also the item can be detached if it was deleted in a previous flush

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  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
>  
> .

-- 
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/0b931af9-a9da-4b91-a34e-2975b73f4a64%40www.fastmail.com.


Re: [sqlalchemy] debugging DetachedInstanceError

2020-04-23 Thread Mike Bayer
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  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
>  
> .

-- 
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.


[sqlalchemy] debugging DetachedInstanceError

2020-04-22 Thread Jonathan Vanasco
I'm trying to figure out how I got a DetatchedInstanceError


DetachedInstanceError: Parent instance  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.