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 09:11:54 +0000 |
| commit | 5a2c1bc07d126ce32efaa157e712a8f3a7457b74 (patch) | |
| tree | c022d548bbb2f325083575c3c4c229ddae9569d7 /tests/backends/sqlite | |
| parent | 0671a461c44ba4cf97e84b6c88413bed332df314 (diff) | |
Fixed #36118 -- Accounted for multiple primary keys in bulk_update max_batch_size.
Co-authored-by: Simon Charette <charette.s@gmail.com>
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, + ) |
