Refs #33374 -- Added tests for multi-table fast-deletion with filters that match everything.

This commit is contained in:
Simon Charette 2022-11-07 20:13:11 +01:00 committed by Mariusz Felisiak
parent 7990d254b0
commit 4b702c832c
1 changed files with 8 additions and 1 deletions

View File

@ -1,7 +1,7 @@
from math import ceil from math import ceil
from django.db import connection, models from django.db import connection, models
from django.db.models import ProtectedError, RestrictedError from django.db.models import ProtectedError, Q, RestrictedError
from django.db.models.deletion import Collector from django.db.models.deletion import Collector
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
@ -776,3 +776,10 @@ class FastDeleteTests(TestCase):
(1, {"delete.Base": 1}), (1, {"delete.Base": 1}),
) )
self.assertIs(Base.objects.exists(), False) self.assertIs(Base.objects.exists(), False)
def test_fast_delete_full_match(self):
avatar = Avatar.objects.create(desc="bar")
User.objects.create(avatar=avatar)
with self.assertNumQueries(1):
User.objects.filter(~Q(pk__in=[]) | Q(avatar__desc="foo")).delete()
self.assertFalse(User.objects.exists())