From 4b702c832cd550fe682ef37a69e93866815b9123 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 7 Nov 2022 20:13:11 +0100 Subject: [PATCH] Refs #33374 -- Added tests for multi-table fast-deletion with filters that match everything. --- tests/delete/tests.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/delete/tests.py b/tests/delete/tests.py index d03492bb6f..b14e10ff01 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -1,7 +1,7 @@ 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())