#12953: Generic-related objects are cascade-deleted, but the cascade does not
extend beyond them
---------------------------------------------------+------------------------
          Reporter:  carljm                        |         Owner:  carljm
            Status:  new                           |     Milestone:  1.2   
         Component:  Database layer (models, ORM)  |       Version:  SVN   
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by carljm):

  * has_patch:  0 => 1

Comment:

 Attached a thorough fix that takes advantage of the fact that M2M
 intermediaries are now always models, which means _collect_sub_objects can
 now take care of both GenericRelations and M2Ms, and
 DeleteQuery.delete_batch_related() is no longer needed. This fixes
 cascades for generic relations, makes the ORM deletion logic clearer
 (since it's all in one place) and as a side benefit removes the ORM's last
 remaining dependency on django.contrib.

 The one possible concern is performance. This will be slower for M2Ms, as
 m2m intermediaries are now instantiated and added to the
 _collect_sub_objects collector; the question is how much slower. I'm
 seeing about a 1% increase in overall test suite runtime, but what is
 really needed is a profiled benchmark that does a lot of deletions with
 various related objects.

 One possible low-hanging fruit would be to check whether an m2m
 intermediary model is auto-created, and if so just directly add it to
 seen_objs instead of calling _collect_sub_objects on it (as an auto-
 created m2m model will not have other FKs pointing to it). Not sure how
 much this will help. It may be that what's really needed is a more
 thorough rethinking of _collect_sub_objects for better efficiency; even
 the existing _collect_sub_objects code was less than ideal in that regard.

 Feedback welcome.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12953#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to