#2749: [patch] Deleting object with generic relation does not work with one to 
one
------------------------+---------------------------------------------------
   Reporter:  clong     |                Owner:  adrian        
     Status:  reopened  |            Component:  Core framework
    Version:  SVN       |           Resolution:                
   Keywords:            |                Stage:  Unreviewed    
  Has_patch:  1         |           Needs_docs:  0             
Needs_tests:  0         |   Needs_better_patch:  0             
------------------------+---------------------------------------------------
Comment (by Favo <[EMAIL PROTECTED]>):

 The implement for GenericRelation is totally wrong. it should not inherit
 from M anytoManyRelation -- that cause serious delete bug. because I have
 not time to implement a new relation class for generic, and the current
 support generic look up search with our patch. we just hide the delete
 function for short term.
 
 For long term we need help django implement a new GenericRelation which
 support generic lookup and sync delete(with test).
 
 I paste the patch here because it's not a real solution
 {{{
 Index: django/db/models/query.py
 ===================================================================
 --- django/db/models/query.py   (revision 5321)
 +++ django/db/models/query.py   (revision 5322)
 @@ -926,6 +926,8 @@
 
          pk_list = [pk for pk,instance in seen_objs[cls]]
          for related in cls._meta.get_all_related_many_to_many_objects():
 +            if related.field.__class__.__name__ == 'GenericRelation':
 +                continue
              for offset in range(0, len(pk_list),
 GET_ITERATOR_CHUNK_SIZE):
                  cursor.execute("DELETE FROM %s WHERE %s IN (%s)" % \
                      (qn(related.field.m2m_db_table()),
 @@ -933,6 +935,8 @@
                          ','.join(['%s' for pk in
 pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE]])),
 pk_list[offset:offset+GET_ITERATOR_CHUNK_SIZE])
          for f in cls._meta.many_to_many:
 +            if f.__class__.__name__ == 'GenericRelation':
 +                continue
              for offset in range(0, len(pk_list),
 GET_ITERATOR_CHUNK_SIZE):
                  cursor.execute("DELETE FROM %s WHERE %s IN (%s)" % \
                      (qn(f.m2m_db_table()), qn(f.m2m_column_name()),
 
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/2749#comment:5>
Django Code <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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to