Fixed #36118 -- Accounted for multiple primary keys in bulk_update max_batch_size.

Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
Sarah Boyce 2025-01-27 10:28:21 +01:00
parent 0671a461c4
commit 5a2c1bc07d
6 changed files with 69 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import unittest
from django.core.management.color import no_style
from django.db import connection
from django.db import connection, models
from django.test import TestCase
from ..models import Person, Tag
@ -86,3 +86,25 @@ class SQLiteOperationsTests(TestCase):
"zzz'",
statements[-1],
)
def test_bulk_batch_size(self):
self.assertEqual(connection.ops.bulk_batch_size([], [Person()]), 1)
first_name_field = Person._meta.get_field("first_name")
last_name_field = Person._meta.get_field("last_name")
self.assertEqual(
connection.ops.bulk_batch_size([first_name_field], [Person()]), 500
)
self.assertEqual(
connection.ops.bulk_batch_size(
[first_name_field, last_name_field], [Person()]
),
connection.features.max_query_params // 2,
)
composite_pk = models.CompositePrimaryKey("first_name", "last_name")
composite_pk.fields = [first_name_field, last_name_field]
self.assertEqual(
connection.ops.bulk_batch_size(
[composite_pk, first_name_field], [Person()]
),
connection.features.max_query_params // 3,
)