diff --git a/docs/releases/1.8.7.txt b/docs/releases/1.8.7.txt index 8ffae59b21..df0ff41159 100644 --- a/docs/releases/1.8.7.txt +++ b/docs/releases/1.8.7.txt @@ -39,3 +39,6 @@ Bugfixes * Fixed ``Model.refresh_from_db()`` updating of ``ForeignKey`` fields with ``on_delete=models.SET_NULL`` (:ticket:`25715`). + +* Fixed a duplicate query regression in 1.8 on proxied model deletion + (:ticket:`25685`). diff --git a/tests/delete/models.py b/tests/delete/models.py index a7838c4510..60e7f5957c 100644 --- a/tests/delete/models.py +++ b/tests/delete/models.py @@ -99,6 +99,12 @@ class Avatar(models.Model): desc = models.TextField(null=True) +# This model is used to test a duplicate query regression (#25685) +class AvatarProxy(Avatar): + class Meta: + proxy = True + + class User(models.Model): avatar = models.ForeignKey(Avatar, models.CASCADE, null=True) diff --git a/tests/delete/tests.py b/tests/delete/tests.py index 9e383acb4e..663a22791b 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -414,6 +414,17 @@ class DeletionTests(TestCase): for k, v in existed_objs.items(): self.assertEqual(deleted_objs[k], v) + def test_proxied_model_duplicate_queries(self): + """ + #25685 - Deleting instances of a model with existing proxy + classes should not issue multiple queries during cascade + deletion of referring models. + """ + avatar = Avatar.objects.create() + # One query for the Avatar table and a second for the User one. + with self.assertNumQueries(2): + avatar.delete() + class FastDeleteTests(TestCase):