diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-27 10:28:21 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-29 10:25:00 +0100 |
| commit | a469397dd36a8691d77539e20a5112b0761e116a (patch) | |
| tree | 12f44daa93c5c14489425921cdceb285921e60d2 /tests/backends/sqlite | |
| parent | 4aa2cd6f68cd06ddbbb227d2f63efc2bd51054ca (diff) | |
[5.2.x] Fixed #36118 -- Accounted for multiple primary keys in bulk_update max_batch_size.
Co-authored-by: Simon Charette <charette.s@gmail.com>
Backport of 5a2c1bc07d126ce32efaa157e712a8f3a7457b74 from main.
Diffstat (limited to 'tests/backends/sqlite')
| -rw-r--r-- | tests/backends/sqlite/test_operations.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/backends/sqlite/test_operations.py b/tests/backends/sqlite/test_operations.py index 3ff055248d..10cbffdf80 100644 --- a/tests/backends/sqlite/test_operations.py +++ b/tests/backends/sqlite/test_operations.py @@ -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, + ) |
