mirror of
https://github.com/django/django.git
synced 2025-08-22 09:49:12 +00:00
Fixed #36430 -- Removed artificially low limit on single field bulk operations on SQLite.
This commit is contained in:
parent
fb0d463b1f
commit
a2ce4900a6
@ -32,9 +32,6 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
"""
|
"""
|
||||||
SQLite has a variable limit defined by SQLITE_LIMIT_VARIABLE_NUMBER
|
SQLite has a variable limit defined by SQLITE_LIMIT_VARIABLE_NUMBER
|
||||||
(reflected in max_query_params).
|
(reflected in max_query_params).
|
||||||
|
|
||||||
If there's only a single field to insert, the limit is 500
|
|
||||||
(SQLITE_MAX_COMPOUND_SELECT).
|
|
||||||
"""
|
"""
|
||||||
fields = list(
|
fields = list(
|
||||||
chain.from_iterable(
|
chain.from_iterable(
|
||||||
@ -46,9 +43,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
for field in fields
|
for field in fields
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if len(fields) == 1:
|
if fields:
|
||||||
return 500
|
|
||||||
elif len(fields) > 1:
|
|
||||||
return self.connection.features.max_query_params // len(fields)
|
return self.connection.features.max_query_params // len(fields)
|
||||||
else:
|
else:
|
||||||
return len(objs)
|
return len(objs)
|
||||||
|
@ -93,7 +93,8 @@ class SQLiteOperationsTests(TestCase):
|
|||||||
first_name_field = Person._meta.get_field("first_name")
|
first_name_field = Person._meta.get_field("first_name")
|
||||||
last_name_field = Person._meta.get_field("last_name")
|
last_name_field = Person._meta.get_field("last_name")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
connection.ops.bulk_batch_size([first_name_field], [Person()]), 500
|
connection.ops.bulk_batch_size([first_name_field], [Person()]),
|
||||||
|
connection.features.max_query_params,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
connection.ops.bulk_batch_size(
|
connection.ops.bulk_batch_size(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user