Fixed #36143 -- Made max_query_params respect SQLITE_LIMIT_VARIABLE_NUMBER.

Co-authored-by: Xavier Frankline <xf.xavierfrank@gmail.com>
This commit is contained in:
Sage Abdullah 2025-05-08 09:10:44 +02:00 committed by Sarah Boyce
parent 38660a612c
commit 358fd21c47
4 changed files with 55 additions and 3 deletions

View file

@ -1,3 +1,4 @@
import sqlite3
import unittest
from django.core.management.color import no_style
@ -108,3 +109,32 @@ class SQLiteOperationsTests(TestCase):
),
connection.features.max_query_params // 3,
)
def test_bulk_batch_size_respects_variable_limit(self):
first_name_field = Person._meta.get_field("first_name")
last_name_field = Person._meta.get_field("last_name")
limit_name = sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER
current_limit = connection.features.max_query_params
self.assertEqual(
connection.ops.bulk_batch_size(
[first_name_field, last_name_field], [Person()]
),
current_limit // 2,
)
new_limit = min(42, current_limit)
try:
connection.connection.setlimit(limit_name, new_limit)
self.assertEqual(
connection.ops.bulk_batch_size(
[first_name_field, last_name_field], [Person()]
),
new_limit // 2,
)
finally:
connection.connection.setlimit(limit_name, current_limit)
self.assertEqual(
connection.ops.bulk_batch_size(
[first_name_field, last_name_field], [Person()]
),
current_limit // 2,
)