mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #31474 -- Made QuerySet.delete() not return the number of deleted objects if it's zero.
This commit is contained in:
parent
c86201b6ed
commit
35a67b3731
@ -408,6 +408,7 @@ class Collector:
|
||||
# fast deletes
|
||||
for qs in self.fast_deletes:
|
||||
count = qs._raw_delete(using=self.using)
|
||||
if count:
|
||||
deleted_counter[qs.model._meta.label] += count
|
||||
|
||||
# update fields
|
||||
@ -426,6 +427,7 @@ class Collector:
|
||||
query = sql.DeleteQuery(model)
|
||||
pk_list = [obj.pk for obj in instances]
|
||||
count = query.delete_batch(pk_list, self.using)
|
||||
if count:
|
||||
deleted_counter[model._meta.label] += count
|
||||
|
||||
if not model._meta.auto_created:
|
||||
|
@ -522,11 +522,10 @@ class DeletionTests(TestCase):
|
||||
existed_objs = {
|
||||
R._meta.label: R.objects.count(),
|
||||
HiddenUser._meta.label: HiddenUser.objects.count(),
|
||||
A._meta.label: A.objects.count(),
|
||||
MR._meta.label: MR.objects.count(),
|
||||
HiddenUserProfile._meta.label: HiddenUserProfile.objects.count(),
|
||||
}
|
||||
deleted, deleted_objs = R.objects.all().delete()
|
||||
self.assertCountEqual(deleted_objs.keys(), existed_objs.keys())
|
||||
for k, v in existed_objs.items():
|
||||
self.assertEqual(deleted_objs[k], v)
|
||||
|
||||
@ -550,13 +549,13 @@ class DeletionTests(TestCase):
|
||||
existed_objs = {
|
||||
R._meta.label: R.objects.count(),
|
||||
HiddenUser._meta.label: HiddenUser.objects.count(),
|
||||
A._meta.label: A.objects.count(),
|
||||
MR._meta.label: MR.objects.count(),
|
||||
HiddenUserProfile._meta.label: HiddenUserProfile.objects.count(),
|
||||
M.m2m.through._meta.label: M.m2m.through.objects.count(),
|
||||
}
|
||||
deleted, deleted_objs = r.delete()
|
||||
self.assertEqual(deleted, sum(existed_objs.values()))
|
||||
self.assertCountEqual(deleted_objs.keys(), existed_objs.keys())
|
||||
for k, v in existed_objs.items():
|
||||
self.assertEqual(deleted_objs[k], v)
|
||||
|
||||
@ -694,7 +693,7 @@ class FastDeleteTests(TestCase):
|
||||
with self.assertNumQueries(1):
|
||||
self.assertEqual(
|
||||
User.objects.filter(avatar__desc='missing').delete(),
|
||||
(0, {'delete.User': 0})
|
||||
(0, {}),
|
||||
)
|
||||
|
||||
def test_fast_delete_combined_relationships(self):
|
||||
|
Loading…
Reference in New Issue
Block a user