Ticket #16128: 16128.4.patch

File 16128.4.patch, 2.8 KB (added by claudep, 4 years ago)

Patch with test and fix

  • django/db/models/deletion.py

    diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
    index 310e3af..f9be668 100644
    a b class Collector(object): 
    202202            for model in models:
    203203                if model in sorted_models:
    204204                    continue
    205                 dependencies = self.dependencies.get(model)
     205                # Dependencies keys are not proxy models
     206                base_model = model._meta.proxy and model._meta.proxy_for_model or model
     207                dependencies = self.dependencies.get(base_model)
    206208                if not (dependencies and dependencies.difference(sorted_models)):
    207209                    sorted_models.append(model)
    208210                    found = True
  • tests/modeltests/proxy_models/models.py

    diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
    index 90d54d9..3a89a5f 100644
    a b than using a new table of their own. This allows them to act as simple proxies, 
    55providing a modified interface to the data from the base class.
    66"""
    77
     8from django.contrib.auth.models import User as AuthUser
    89from django.contrib.contenttypes.models import ContentType
    910from django.db import models
    1011
    class Improvement(Issue): 
    161162
    162163class ProxyImprovement(Improvement):
    163164    class Meta:
    164         proxy = True
    165  No newline at end of file
     165        proxy = True
     166
     167
     168class AuthUserProxy(AuthUser):
     169    class Meta:
     170        proxy = True
     171
     172class Profile(models.Model):
     173    user = models.ForeignKey(AuthUser)
  • tests/modeltests/proxy_models/tests.py

    diff --git a/tests/modeltests/proxy_models/tests.py b/tests/modeltests/proxy_models/tests.py
    index 0a46a25..226369d 100644
    a b from models import MyPersonProxy, Abstract, OtherPerson, User, UserProxy 
    1111from models import UserProxyProxy, Country, State, StateProxy, TrackerUser
    1212from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug
    1313from models import ProxyBug, ProxyImprovement
     14from models import AuthUser, AuthUserProxy, Profile
    1415
    1516class ProxyModelTests(TestCase):
    1617    def test_same_manager_queries(self):
    class ProxyModelTests(TestCase): 
    312313        management.call_command('loaddata', 'mypeople.json', verbosity=0, commit=False)
    313314        p = MyPerson.objects.get(pk=100)
    314315        self.assertEqual(p.name, 'Elvis Presley')
     316
     317    def test_delete_cascade_to_proxy_objects(self):
     318        """
     319        Test that delete() cascades to proxy objects. Regression for #16128.
     320        """
     321        proxy_joe = AuthUserProxy.objects.create()
     322        joe_s_profile = Profile.objects.create(user=proxy_joe)
     323        self.assertEqual(Profile.objects.count(), 1)
     324        proxy_joe.delete()
     325        self.assertEqual(Profile.objects.count(), 0)
Back to Top