OK Dan -

Faced with the prospect of heavily weighing down all lazy load and  
eager load operations with tons of "hasparent" flag settings for  
every referring property on every loaded object, I instead changed  
the semantics of "is_orphan" a bit.  when you ask the mapper for  
is_orphan(), it now determines an extra flag "optimistic".  which  
says, if this instance was loaded from the database, and we cant find  
any hasparent flag (i.e. neither True nor False), assume its not an  
orphan.  if the instance was not loaded from the  DB (i.e. transient/ 
pending), and we cant find a flag, then assume it *is* an orphan.  as  
soon as any manipulations of the instance occur in the user's  
application, the "hasparent" flag is immediately set to True or False  
where it then remains, and the "optimistic" flag then has no bearing  
on the check.

so rev 1839 has my first reaction to the test case you sent, then  
1840 has this latest version, with three new unit tests.   try it out !

- mike

On Sep 1, 2006, at 11:55 AM, dmiller wrote:

>> this is a very serious issue !
>
> Yes it is! All of a sudden all kinds of random records were being  
> deleted in my app for no reason at all! Luckily it was just test  
> data...
>
>>   the fix for your test is pretty easy, when the lazy load  
>> operation occurs, it has to make sure it sets up that "hasparent"  
>> relationship properly on the newly loaded objects.
>>
>> but im still fixing it for eager loading, which currently bypasses  
>> the attribute manager (that has to change).
>>
>> i am extremely glad you found this bug before I released.  because  
>> look at the symptom:
>>
>>         m = mapper(User, users, properties={
>>             'addresses':relation(Address, cascade="all,delete- 
>> orphan", lazy=False)
>>         })
>>         mapper(Address, addresses)
>>
>>         s = create_session()
>>         q = s.query(m)
>>         user = q.get(7)
>>         user.addresses[0].email_address='foo'
>>         s.flush()
>>
>> because of our enhancement to the unitofwork to double-check for  
>> orphans, this flush sees the "Address" object as an orphan and  
>> deletes it !!!
>
> Yes, that's exactly what I was seeing in my program. Its funny that  
> I couldn't make a test to reproduce it since it's so easy to do now  
> that we know how. Let me know when it's fixed. Thanks.
>
> ~ Daniel
>


-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to