summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-27 09:53:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-27 10:35:42 +0200
commit7ad7034054c10bfa919ceec4623fa7f30a68bba2 (patch)
tree85572aecb66cb071a91b967ece22a86a4d571a96 /tests
parent727a154094a2d565e3d4e9e11cd80dda46cc227d (diff)
downloaddjango-7ad7034054c10bfa919ceec4623fa7f30a68bba2.tar.gz
[3.2.x] Refs #32682 -- Fixed QuerySet.delete() crash on querysets with self-referential subqueries on MySQL.
Backport of 4074f38e1dcc93b859bbbfd6abd8441c3bca36b3 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/delete_regress/models.py1
-rw-r--r--tests/delete_regress/tests.py14
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/delete_regress/models.py b/tests/delete_regress/models.py
index 90eae1ba1c..e06da1288b 100644
--- a/tests/delete_regress/models.py
+++ b/tests/delete_regress/models.py
@@ -24,6 +24,7 @@ class Person(models.Model):
class Book(models.Model):
pagecount = models.IntegerField()
+ owner = models.ForeignKey('Child', models.CASCADE, null=True)
class Toy(models.Model):
diff --git a/tests/delete_regress/tests.py b/tests/delete_regress/tests.py
index 97a7d6ba02..fe758eab74 100644
--- a/tests/delete_regress/tests.py
+++ b/tests/delete_regress/tests.py
@@ -1,6 +1,7 @@
import datetime
from django.db import connection, models, transaction
+from django.db.models import Exists, OuterRef
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
)
@@ -355,6 +356,19 @@ class DeleteTests(TestCase):
self.assertEqual(researcher2.primary_contact, contact2)
self.assertIsNone(researcher2.secondary_contact)
+ def test_self_reference_with_through_m2m_at_second_level(self):
+ toy = Toy.objects.create(name='Paints')
+ child = Child.objects.create(name='Juan')
+ Book.objects.create(pagecount=500, owner=child)
+ PlayedWith.objects.create(child=child, toy=toy, date=datetime.date.today())
+ Book.objects.filter(Exists(
+ Book.objects.filter(
+ pk=OuterRef('pk'),
+ owner__toys=toy.pk,
+ ),
+ )).delete()
+ self.assertIs(Book.objects.exists(), False)
+
class DeleteDistinct(SimpleTestCase):
def test_disallowed_delete_distinct(self):