Jay Parlar came across this bug while testing the POP branch. It appears that this code, when using generic relations:
for related in cls._meta.get_all_related_many_to_many_objects():
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()),
qn(related.field.m2m_reverse_name()),
For the m2m_reverse_name returns the one-to-one id name (in the example Jay Parlar gives it's user_id) instead of the id used in the generic relation (in POP branch it's model_id or owner_id). The below patch seems to have fixed this problem.
Patch:
--- django/db/models/fields/generic.py (revision 3668)
+++ django/db/models/fields/generic.py (working copy)
@@ -117,7 +117,7 @@
return self.object_id_field_name
def m2m_reverse_name(self):
- return self.model._meta.pk.attname
+ return self.object_id_field_name
def contribute_to_class(self, cls, name):
super(GenericRelation, self).contribute_to_class(cls, name)