1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #36143 -- Tested bulk_batch_size limit for bulk_update and bulk_create.

This commit is contained in:
Sage Abdullah
2025-05-08 09:10:00 +02:00
committed by Sarah Boyce
parent 37f2a77c72
commit 38660a612c
2 changed files with 19 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
import datetime
from math import ceil
from django.core.exceptions import FieldDoesNotExist
from django.db import connection
from django.db.models import F
from django.db.models.functions import Lower
from django.db.utils import IntegrityError
@@ -69,6 +71,15 @@ class BulkUpdateNoteTests(TestCase):
with self.assertNumQueries(len(self.notes)):
Note.objects.bulk_update(self.notes, fields=["note"], batch_size=1)
def test_max_batch_size(self):
max_batch_size = connection.ops.bulk_batch_size(
# PK is used twice, see comment in bulk_update().
[Note._meta.pk, Note._meta.pk, Note._meta.get_field("note")],
self.notes,
)
with self.assertNumQueries(ceil(len(self.notes) / max_batch_size)):
Note.objects.bulk_update(self.notes, fields=["note"])
def test_unsaved_models(self):
objs = self.notes + [Note(note="test", misc="test")]
msg = "All bulk_update() objects must have a primary key set."