On Feb 26, 2011, at 1:17 PM, Chris Withers wrote:

> On 26/02/2011 15:50, Michael Bayer wrote:
>> 
>>> On 25/02/2011 17:13, Michael Bayer wrote:
>>>> can't reproduce.  See attached.    This test includes randomization of all 
>>>> key data structures in the UOW which smokes out any issues in dependency 
>>>> sorting.
>>> 
>>> Okay, so after about an hour of stripping down code, please find attached a 
>>> minimal reproducible test case.
>> 
>> this is a simple mistake.  This:
>> 
>> session.add(Grant(username=user.username))
>> 
>> is this:
>> 
>> x = Parent(id=1)
>> y = Child(parent_id=1)
>> 
>> -->  commit
>> 
>> How is x.children to know that "y" is in any way related to x ?
> 
> The surprise for me is that the statements aren't executed in order.
> 
> I did session.add(user) before I did 
> session.add(Grant(username=user.username)), so why aren't the statements 
> executed in order?
> 
> More interestingly, why does the use of sessionmaker versus the use of the 
> standard Session class make a difference?

the unit of work issues INSERTS in order for a single kind of entity.    It 
doesn't do that across all entities since the dependency order between entities 
takes precedence.    Such as here if you did in fact set up Parent.children for 
one or more objects, the UOW sorts entities in order of dependency.     Its new 
in 0.6 that Parent/Child are not sorted by dependency if they have no 
relationship to each other, but if you had a second Parent/Child which did have 
a relationship in the flush, then all the Parents would be first and all the 
Childs second (since common entities are batched together unless there are 
inter-row dependencies).   This all has to do with the flush process being as 
fast, batched, and memory-efficient as possible.



> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>           - http://www.simplistix.co.uk

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to