Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed review issues noted by claudep. Refs #17788.

The issues fixed were some comment issues, use of '//' operator instead
of '/' operator. In addition, added some defensive programming
enchantments for division by zero and zero sized batches.
  • Loading branch information...
1 parent d4eacac commit 332fb9308c39249cdd38a034a3565778636c373b @akaariai committed
7 django/db/backends/
@@ -478,13 +478,10 @@ def autoinc_sql(self, table, column):
def bulk_batch_size(self, fields, objs):
Returns the maximum allowed batch size for the backend. The fields
- are the fields we will be inserting in the batch, the objs contains
+ are the fields going to be inserted in the batch, the objs contains
all the objects to be inserted.
- The default return value of None means unlimited. This method must
- always return a valuer greater than 0.
- return None
+ return len(objs)
def date_extract_sql(self, lookup_type, field_name):
5 django/db/backends/sqlite3/
@@ -106,9 +106,10 @@ def _supports_stddev(self):
class DatabaseOperations(BaseDatabaseOperations):
def bulk_batch_size(self, fields, objs):
- SQLite has a limit of 1000 variables per query.
+ SQLite has a compile-time default (SQLITE_LIMIT_VARIABLE_NUMBER) of
+ 999 variables per query.
- return max(999 / len(fields), 1)
+ return (999 // len(fields)) if len(fields) > 0 else len(objs)
def date_extract_sql(self, lookup_type, field_name):
# sqlite doesn't support extract, so we fake it with the user-defined
6 django/db/models/
@@ -871,10 +871,8 @@ def _batched_insert(self, objs, fields, batch_size):
if not objs:
- connection = connections[self.db]
- batch_size = (batch_size
- or connection.ops.bulk_batch_size(fields, objs)
- or len(objs))
+ ops = connections[self.db].ops
+ batch_size = (batch_size or max(ops.bulk_batch_size(fields, objs), 1))
for batch in [objs[i:i+batch_size]
for i in range(0, len(objs), batch_size)]:
self.model._base_manager._insert(batch, fields=fields,

0 comments on commit 332fb93

Please sign in to comment.
Something went wrong with that request. Please try again.