On Apr 2, 2007, at 10:35 PM, Barry Warsaw wrote:

>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Our populate_instance() checks the isnew flag and if this is true, it
> does not call our initialization stuff.  Now, I don't really see the
> isnew flag documented, so I assumed it was only called when the
> object was initially loaded from the database, but apparently it's
> true /every/ time the object is loaded.  So when I session.expire()
> it and then subsequently load it, populate_instance() gets called
> with isnew=True.  The causes our application-specific initialization
> stuff to get called on an existing MailList object, and this is what
> blows away our lock attribute.
>
> I guess that if the documentation for isnew in append_result() is the
> same as isnew in populate_instance() then indeed we'll need that
> extra check.  Is that correct?
>

OK, yes, im sorry about the lack of docs for "isnew"...sometimes i  
subconsciously want to see how long it takes for someone to ask me  
about something (bad habit) although in this case that flag is over a  
year old and i think youre the first :)

"isnew" is used to indicate that we are going to populate the  
instance with data from the database, *and* that this particular row  
is the first row in the result which has indicated the presence of  
this entity (i.e. the primary key points to it).   this implies that  
populate_instance() can be called *multiple times* for the instance,  
if multiple successive rows all contain its particular primary key.    
this is how SA deals with the products of eager loads and other  
joins, where many rows contain the same entity identity in a number  
of successive rows corresponding to the total product of eagerly  
loaded child items - the normal populate_instance() just delegates  
the "populate this attribute" task onto MapperProperty objects that  
represent each attribute. for the MapperProperty objects that  
represent eager loaders, they unconditionally send the row off to  
their child mappers to look at the row, where it then goes into its  
own populate_instance() process with a possibly True isnew flag.

so basically, "isnew" means "populate attributes" and if its false it  
means "we already did this entity".




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