Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…c 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
  • Loading branch information...
commit 75146a3d7b85580244ebeda36241396290a0de15 1 parent 4043521
@kmtracey kmtracey authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 django/db/models/sql/subqueries.py
View
10 django/db/models/sql/subqueries.py
@@ -58,15 +58,19 @@ def delete_batch_related(self, pk_list):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.