Made QuerySet.bulk_update() raise an error when batch_size is zero.

This commit is contained in:
Ebram Shehata 2022-06-13 06:25:25 +02:00 committed by GitHub
parent e96320c917
commit 4996eaa7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -845,7 +845,7 @@ class QuerySet:
"""
Update the given fields in each of the given objects in the database.
"""
if batch_size is not None and batch_size < 0:
if batch_size is not None and batch_size <= 0:
raise ValueError("Batch size must be a positive integer.")
if not fields:
raise ValueError("Field names must be given to bulk_update().")

View File

@ -125,6 +125,8 @@ class BulkUpdateTests(TestCase):
msg = "Batch size must be a positive integer."
with self.assertRaisesMessage(ValueError, msg):
Note.objects.bulk_update([], fields=["note"], batch_size=-1)
with self.assertRaisesMessage(ValueError, msg):
Note.objects.bulk_update([], fields=["note"], batch_size=0)
def test_nonexistent_field(self):
with self.assertRaisesMessage(