summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAhmet Kucuk <ahmetkucuk92@gmail.com>2019-10-01 13:13:19 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-21 11:46:44 +0200
commit09578f6dfb757c55f107e30a85434cedeb47465a (patch)
tree1e6d077b4c99f71deba9af60051d8b29e73d5efd /django
parent312049091288dbba2299de8d07ea3e3311ed7238 (diff)
Fixed #30827 -- Made batch_size arg of QuerySet.bulk_create() respect DatabaseOperations.bulk_batch_size().
Thanks Chetan Khanna for tests.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 794e0faae7..92349cd0c5 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1209,7 +1209,8 @@ class QuerySet:
if ignore_conflicts and not connections[self.db].features.supports_ignore_conflicts:
raise NotSupportedError('This database backend does not support ignoring conflicts.')
ops = connections[self.db].ops
- batch_size = (batch_size or max(ops.bulk_batch_size(fields, objs), 1))
+ max_batch_size = max(ops.bulk_batch_size(fields, objs), 1)
+ batch_size = min(batch_size, max_batch_size) if batch_size else max_batch_size
inserted_rows = []
bulk_return = connections[self.db].features.can_return_rows_from_bulk_insert
for item in [objs[i:i + batch_size] for i in range(0, len(objs), batch_size)]: