On Jan 9, 2014, at 4:02 PM, Paul Moore <[email protected]> wrote:

> The real app is basically just a lot more complex (releases have 4 child 
> lists like urls, my example adds multiple objects in each list. The app fails 
> with an integrity error because a url has a null request_id. In actual fact, 
> the hierarchy all gets built up properly in the end, but it appears that 
> something is trying to save the children before all of the links are set up.
> 
> If I remove nullable=False from the foreign keys, it works fine.
> 
> I think one of the error tracebacks (sorry, I lost them in other output) 
> mentioned autoflush - could the ORM be trying to flush bits of the hierarchy 
> before it's complete? Is there a better fix than removing the nullable=False 
> constraints?

absolutely, which is why the “no_autoflush” contextmanager exists:

http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html?highlight=no_autoflush#sqlalchemy.orm.session.Session.no_autoflush

the stack trace you’re getting will give you clues to where this context 
manager should go.  You’ll see the word “autoflush” in the stack trace, and 
from there you can trace up to see the specific operation in your app that is 
triggering it.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to