Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Karen Tracey authored January 29, 2010

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  django/db/models/sql/subqueries.py
10  django/db/models/sql/subqueries.py
@@ -58,15 +58,19 @@ def delete_batch_related(self, pk_list):
58 58
 
59 59
         for f in cls._meta.many_to_many:
60 60
             w1 = self.where_class()
  61
+            db_prep_value = None
61 62
             if isinstance(f, generic.GenericRelation):
62 63
                 from django.contrib.contenttypes.models import ContentType
63  
-                field = f.rel.to._meta.get_field(f.content_type_field_name)
64  
-                w1.add((Constraint(None, field.column, field), 'exact',
  64
+                ct_field = f.rel.to._meta.get_field(f.content_type_field_name)
  65
+                w1.add((Constraint(None, ct_field.column, ct_field), 'exact',
65 66
                         ContentType.objects.get_for_model(cls).id), AND)
  67
+                id_field = f.rel.to._meta.get_field(f.object_id_field_name)
  68
+                db_prep_value = id_field.get_db_prep_value
66 69
             for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
67 70
                 where = self.where_class()
68 71
                 where.add((Constraint(None, f.m2m_column_name(), f), 'in',
69  
-                        pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]),
  72
+                        map(db_prep_value,
  73
+                            pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE])),
70 74
                         AND)
71 75
                 if w1:
72 76
                     where.add(w1, AND)

0 notes on commit 75146a3

Please sign in to comment.
Something went wrong with that request. Please try again.