Refs -- Added tests for multi-table fast-deletion with filters that match everything.
from math import ceil
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.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
@@ -776,3 +776,10 @@ class FastDeleteTests(TestCase):
(1, {"delete.Base": 1}),
)
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())
