Commit 75146a3d authored by Karen Tracey's avatar Karen Tracey
Browse files

[1.1.X] Really this time -- fixed #12721: Ensured objects with generic...

[1.1.X] Really this time -- fixed #12721: Ensured objects with generic relations that use non-integer object ID fields can be deleted on PostgreSQL. Thanks much carljm for patch and Russ for review. 

Remainder of r12353 from trunk, previous attempt only picked up the new tests.



git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12356 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 4043521f
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -58,15 +58,19 @@ class DeleteQuery(Query):

        for f in cls._meta.many_to_many:
            w1 = self.where_class()
            db_prep_value = None
            if isinstance(f, generic.GenericRelation):
                from django.contrib.contenttypes.models import ContentType
                field = f.rel.to._meta.get_field(f.content_type_field_name)
                w1.add((Constraint(None, field.column, field), 'exact',
                ct_field = f.rel.to._meta.get_field(f.content_type_field_name)
                w1.add((Constraint(None, ct_field.column, ct_field), 'exact',
                        ContentType.objects.get_for_model(cls).id), AND)
                id_field = f.rel.to._meta.get_field(f.object_id_field_name)
                db_prep_value = id_field.get_db_prep_value
            for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
                where = self.where_class()
                where.add((Constraint(None, f.m2m_column_name(), f), 'in',
                        pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]),
                        map(db_prep_value,
                            pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE])),
                        AND)
                if w1:
                    where.add(w1, AND)