Ticket #18083: ticket-18083-fix-thanks-to-carljm.diff

File ticket-18083-fix-thanks-to-carljm.diff, 3.7 KB (added by Simon Charette, 12 years ago)
  • django/db/models/deletion.py

    diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
    index 730847e..d8bb8f2 100644
    a b def collect(self, objs, source=None, nullable=False, collect_related=True,  
    154154
    155155        model = new_objs[0].__class__
    156156
    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():
    160161            if ptr:
    161162                parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
    162163                self.collect(parent_objs, source=model,
  • tests/modeltests/proxy_model_inheritance/models.py

    diff --git a/tests/modeltests/proxy_model_inheritance/models.py b/tests/modeltests/proxy_model_inheritance/models.py
    index e69de29..ef9ac6b 100644
    a b  
     1
     2from django.db import models
     3
     4
     5class ConcreteModel(models.Model):
     6    pass
     7
     8class ConcreteModelSubclass(ConcreteModel):
     9    pass
     10
     11class ConcreteModelSubclassProxy(ConcreteModelSubclass):
     12    class Meta:
     13        proxy = True
  • tests/modeltests/proxy_model_inheritance/tests.py

    diff --git a/tests/modeltests/proxy_model_inheritance/tests.py b/tests/modeltests/proxy_model_inheritance/tests.py
    index ae5ab20..94805d9 100644
    a b  
    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 
    91from __future__ import absolute_import
    102
    113import os
     
    146from django.conf import settings
    157from django.core.management import call_command
    168from django.db.models.loading import cache, load_app
    17 from django.test import TransactionTestCase
     9from django.test import TestCase, TransactionTestCase
    1810from django.test.utils import override_settings
    1911
     12from .models import (ConcreteModel, ConcreteModelSubclass,
     13    ConcreteModelSubclassProxy)
     14
    2015
    2116@override_settings(INSTALLED_APPS=('app1', 'app2'))
    2217class 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    """
    2323
    2424    def setUp(self):
    2525        self.old_sys_path = sys.path[:]
    def test_table_exists(self):  
    4141        from .app2.models import NiceModel
    4242        self.assertEqual(NiceModel.objects.all().count(), 0)
    4343        self.assertEqual(ProxyModel.objects.all().count(), 0)
     44
     45class MultiTableInheritanceProxyTest(TestCase):
     46
     47    def test_model_subclass_proxy(self):
     48        """
     49        Deleting an instance of a model proxing a multi-table inherited subclass
     50        might not cascade delete down the whole inheritance chain while doing it
     51        on the proxied concrete class works (as described in #18083).
     52        """
     53        instance = ConcreteModelSubclassProxy.objects.create()
     54        instance.delete()
     55        self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
     56        self.assertEqual(0, ConcreteModelSubclass.objects.count())
     57        self.assertEqual(0, ConcreteModel.objects.count())
Back to Top