Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18083 -- Fixed cascade deletion with proxy model of concrete s…

…ubclass. Thanks Simon Charette for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17887 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f195f1ed2481d34ff56df36cf46ad7d377f2af93 1 parent 6f7aa51
Carl Meyer authored April 09, 2012
7  django/db/models/deletion.py
@@ -154,9 +154,10 @@ def collect(self, objs, source=None, nullable=False, collect_related=True,
154 154
 
155 155
         model = new_objs[0].__class__
156 156
 
157  
-        # Recursively collect parent models, but not their related objects.
158  
-        # These will be found by meta.get_all_related_objects()
159  
-        for parent_model, ptr in model._meta.parents.iteritems():
  157
+        # Recursively collect concrete model's parent models, but not their
  158
+        # related objects. These will be found by meta.get_all_related_objects()
  159
+        concrete_model = model._meta.concrete_model
  160
+        for ptr in concrete_model._meta.parents.itervalues():
160 161
             if ptr:
161 162
                 parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
162 163
                 self.collect(parent_objs, source=model,
13  tests/modeltests/proxy_model_inheritance/models.py
... ...
@@ -0,0 +1,13 @@
  1
+
  2
+from django.db import models
  3
+
  4
+
  5
+class ConcreteModel(models.Model):
  6
+    pass
  7
+
  8
+class ConcreteModelSubclass(ConcreteModel):
  9
+    pass
  10
+
  11
+class ConcreteModelSubclassProxy(ConcreteModelSubclass):
  12
+    class Meta:
  13
+        proxy = True
34  tests/modeltests/proxy_model_inheritance/tests.py
... ...
@@ -1,11 +1,3 @@
1  
-"""
2  
-XX. Proxy model inheritance
3  
-
4  
-Proxy model inheritance across apps can result in syncdb not creating the table
5  
-for the proxied model (as described in #12286).  This test creates two dummy
6  
-apps and calls syncdb, then verifies that the table has been created.
7  
-"""
8  
-
9 1
 from __future__ import absolute_import
10 2
 
11 3
 import os
@@ -14,12 +6,20 @@
14 6
 from django.conf import settings
15 7
 from django.core.management import call_command
16 8
 from django.db.models.loading import cache, load_app
17  
-from django.test import TransactionTestCase
  9
+from django.test import TestCase, TransactionTestCase
18 10
 from django.test.utils import override_settings
19 11
 
  12
+from .models import (ConcreteModel, ConcreteModelSubclass,
  13
+    ConcreteModelSubclassProxy)
  14
+
20 15
 
21 16
 @override_settings(INSTALLED_APPS=('app1', 'app2'))
22 17
 class ProxyModelInheritanceTests(TransactionTestCase):
  18
+    """
  19
+    Proxy model inheritance across apps can result in syncdb not creating the table
  20
+    for the proxied model (as described in #12286).  This test creates two dummy
  21
+    apps and calls syncdb, then verifies that the table has been created.
  22
+    """
23 23
 
24 24
     def setUp(self):
25 25
         self.old_sys_path = sys.path[:]
@@ -41,3 +41,19 @@ def test_table_exists(self):
41 41
         from .app2.models import NiceModel
42 42
         self.assertEqual(NiceModel.objects.all().count(), 0)
43 43
         self.assertEqual(ProxyModel.objects.all().count(), 0)
  44
+
  45
+
  46
+class MultiTableInheritanceProxyTest(TestCase):
  47
+
  48
+    def test_model_subclass_proxy(self):
  49
+        """
  50
+        Deleting an instance of a model proxying a multi-table inherited
  51
+        subclass should cascade delete down the whole inheritance chain (see
  52
+        #18083).
  53
+
  54
+        """
  55
+        instance = ConcreteModelSubclassProxy.objects.create()
  56
+        instance.delete()
  57
+        self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
  58
+        self.assertEqual(0, ConcreteModelSubclass.objects.count())
  59
+        self.assertEqual(0, ConcreteModel.objects.count())

0 notes on commit f195f1e

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