mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[3.2.x] Refs #32682 -- Fixed QuerySet.delete() crash on querysets with self-referential subqueries on MySQL.
Backport of 4074f38e1d from main
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user