diff options
| author | JaeHyuck Sa <wogur981208@gmail.com> | 2026-01-15 08:06:06 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-01-16 09:15:53 -0500 |
| commit | b98075dc6205374746cf1ad6d3533b9a1d9cf22e (patch) | |
| tree | 2c227604a0fd4e8ac7572942592557b9323e7709 /django/db/backends/base/operations.py | |
| parent | 07a16407452f5b62594661ae7ae589eca8cccd4d (diff) | |
Refs #36822 -- Hoisted bulk_batch_size() implementations to base backend.
Diffstat (limited to 'django/db/backends/base/operations.py')
| -rw-r--r-- | django/db/backends/base/operations.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index e345701438..fac6215899 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -2,12 +2,14 @@ import datetime import decimal import json from importlib import import_module +from itertools import chain import sqlparse from django.conf import settings from django.db import NotSupportedError, transaction from django.db.models.expressions import Col +from django.db.models.fields.composite import CompositePrimaryKey from django.utils import timezone from django.utils.duration import duration_microseconds from django.utils.encoding import force_str @@ -78,7 +80,17 @@ class BaseDatabaseOperations: are the fields going to be inserted in the batch, the objs contains all the objects to be inserted. """ - return len(objs) + if self.connection.features.max_query_params is None or not fields: + return len(objs) + + return self.connection.features.max_query_params // len( + list( + chain.from_iterable( + field.fields if isinstance(field, CompositePrimaryKey) else [field] + for field in fields + ) + ) + ) def format_for_duration_arithmetic(self, sql): raise NotImplementedError( |
