[sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent Bower
I think I understand why, during a flush(), if I use session.query().get() for an item that was just added during this flush, I don't get the persistent object I might expect because the session still has it as pending even though, logically, it is already persistent. I don't suppose you have

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
On Jan 26, 2012, at 11:28 AM, Kent Bower wrote: I think I understand why, during a flush(), if I use session.query().get() for an item that was just added during this flush, I don't get the persistent object I might expect because the session still has it as pending even though,

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent
Fair enough. I had enough understanding of what must be going on to know flush isn't straightforward, but I'm still glad I asked. Sorry for having not read the documents very well and thanks for your answer, because from it, I surmise that before_flush() *is* safe for session operations,

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
yup, before_flush is made for that, and I've for some time had some vague plans to add some more helpers there so you could get events local to certain kinds of objects in certain kinds of states, meaning it would look a lot like before_update. But looping through .new, .dirty, and .deleted

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent
So, as a typical example of where it seems very natural to use before_update, suppose you need to automatically update the not null sequence of a related table. This but to get the sequence you need to loop over the parent table's collection. You want the sequence to be human friendly

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
On Jan 26, 2012, at 1:21 PM, Kent wrote: So, as a typical example of where it seems very natural to use before_update, suppose you need to automatically update the not null sequence of a related table. This but to get the sequence you need to loop over the parent table's collection.