On May 26, 2010, at 1:33 PM, Dan Ellis wrote:

> On May 26, 9:43 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> You can expire the attribute manually ahead of time if you want it to reload 
>> its value (should be fine within after_commit).
> 
> No, it seems that in after_commit the newly added instance is not yet
> in session.identity_map, so session.expire throws an exception:
> "InvalidRequestError: Instance '<Story at 0x102e46ad0>' is not
> persistent within this Session". At this point I'm confused. Why would
> it not be persistent after a commit? (If I remove the extra code, the
> Story is persisted just fine, so it's not like the transaction is
> failing without the extension.)

its in the identity map after the flush succeeds, which is well before 
after_commit() is called.   

However, you can't really use the Session itself for database access inside of 
after_commit().  There is information on this available here: 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueSession .   Here, your 
after_commit() hooks start fresh with a new session.  If you want to use the 
state of objects from the parent session in the new session without reloading 
from the new transaction, use merge(..., load=False).






-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to