Clarify unack'd write concern not returning the deleted count [ci skip]

This commit is contained in:
Stefan Wojcik 2019-06-26 15:14:43 +02:00
parent ffedd33101
commit 91899acfe5
2 changed files with 9 additions and 1 deletions

View File

@ -483,6 +483,10 @@ class BaseQuerySet(object):
with set_write_concern(queryset._collection, write_concern) as collection:
result = collection.delete_many(queryset._query)
# If we're using an unack'd write concern, we don't really know how
# many items have been deleted at this point, hence we only return
# the count for ack'd ops.
if result.acknowledged:
return result.deleted_count

View File

@ -1858,7 +1858,11 @@ class QuerySetTest(unittest.TestCase):
self.assertEqual(1, BlogPost.objects.count())
def test_delete_edge_case_with_write_concern_0_return_None(self):
"""Return None when write is unacknowledged"""
"""Return None if the delete operation is unacknowledged.
If we use an unack'd write concern, we don't really know how many
documents have been deleted.
"""
p1 = self.Person(name="User Z", age=20).save()
del_result = p1.delete(w=0)
self.assertEqual(None, del_result)