in rev 1817 I modified the unitofwork's reaction to is_orphan()  
within the flush so that it cascades the delete operation (but only  
within the context of the flush) to child objects.  I added your  
latest test to the session test suite and it now passes.

It seems like i usually want to keep objects outside of the session's  
deleted list if at all possible until flush time..but not for any  
good reason except it would be a larger behavior change with unknown  
consequences.

On Aug 22, 2006, at 4:12 PM, dmiller wrote:

>
> On Aug 18, 2006, at 12:29 PM, Michael Bayer wrote:
>
>> I addressed this issue the way I described earlier, that upon setting
>> up a relationship with "delete-orphan", a flag is tacked onto that
>> relatoinship's mapper that "orphans should be deleted" regardless of
>> the presence of any collection with which to cascade from.
>>
>> Also, I did temporarily establish the rule we discussed where save()-
>> ing an orphaned entity will immediately raise an error; however, this
>> is incompatible with the "contextual session" since the entity is
>> added to the session upon construction and would render it impossible
>> to create new entities.    you can see the commented-out check in the
>> changeset if youd like to uncomment it for experimentation.
>>
>> what does happen now if you save() an orphaned entity is that it just
>> doesnt get saved.  we could try to put the check further down at
>> flush time perhaps.
>>
>> also, an interesting effect that I didnt think of came up from this,
>> which is that you now no longer can declare a "delete-orphan" cascade
>> rule on a self-referential relationship....since the root of a tree
>> structure is always an orphan.  (of course, you could have a
>> circularly-linked structure, which probably requires the post_update
>> flag to be set; but i think that case is fringe enough that folks
>> could handle the deletes manually in that case.)
>>
>> so check out the changeset, which includes the two new tests in a new
>> session.py unit test module:
>>
>> http://www.sqlalchemy.org/trac/changeset/1807
>>
>
> OK, since I updated to r1815 things are starting to work better. But
> I'm still having problems with orphaned items being saved. There's a
> test case attached. Here's a quick overview:
>
>          s = create_session()
>          order = Order()
>          s.save(order)
>
>          item = Item()
>          attr = Attribute()
>          item.attributes.append(attr)
>
>          order.items.append(item)
>          order.items.remove(item)
>          s.flush()
>
> The flush() attempts to insert the attribute associated with the item
> even though the item was removed from the order and is therefore
> transient. In other words item is an orphan, but flush() erroneously
> tries to save attr since _is_orphan(attr) returns False. I would
> suggest order.items.remove(item) would cascade to all of item's
> children and register them as deleted as well (just like
> order.items.append(item) causes all of item's children to be save
> ()'d ). Alternately, _is_orphan() could be modified to check all
> parent items and detect if they are orphans as well.
>
> Thanks.
>
> ~ Daniel
>
> P.S. I never actually tried the first patch you had given me
> regarding this issue, do you still want me to do that? I figured you
> had patched it or something better into the trunk in r1807.
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to