Michael Bayer wrote:
> On Dec 11, 2007, at 10:07 AM, King Simon-NFHD78 wrote:
> 
> >
> > I assume the problem is that my date_created column isn't 
> immediately
> > available at the 'after_insert' stage, because it is 
> generated in the
> > SQL INSERT statement, but hasn't been read back from the 
> database yet.
> > Is there a more suitable hook-point than after_insert, where I can
> > safely read values like this?
> >
> 
> this is a thorny issue, while the immediate issue youre having is  
> something that can possibly be smoothed over (probably even by  
> sticking on the _instance_key yourself, not sure if i should 
> recommend  
> that though), its not going to work if say you wanted to look at the  
> foriegn key attributes in an attached collection since they havent  
> been set up yet.
> 
> also the API youre using with get_history() has changed in 
> trunk, itll  
> give you a tuple now of (added, unchanged, deleted).
> 
> there is the notion of SessionExtension which has an after_commit()  
> hook, not sure if that is a viable option here.   I cant go too nuts  
> with all these extension hooks since they all add latency to  
> everything (sorta wishing there were a lot less hooks as it is).
> 

Thanks - I've ignored your warning and stuck on the _instance_key, in
the full knowledge that when it breaks it'll be my own silly fault ;-)
I'll investigate the SessionExtension as a longer-term fix. If
after_commit runs when all attributes are completely up-to-date, and I
can still access the previous and new state via get_history, it sounds
like the right thing to use.

I fully understand your worries about hooks slowing SQLAlchemy down, but
I also think that they are one of the features that makes the ORM so
flexible, and it would be a great shame to lose them. I wonder if there
could be a way of caching all the extension methods so that applying
them would be as fast as possible.

<checks code>

OK, I should have guessed. You've already done that - I see the
ExtensionCarrier checks which methods have been overridden when each
extension is added.

Thanks for your help,

Simon

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

Reply via email to