#27385: Error in bulk_create() when objs length is a multiple plus one of
batch_size
----------------------------------------------+--------------------
Reporter: David Barragán Merino | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
With the model
{{{
from django.db import models
class TestModel(models.Model):
number = models.IntegerField()
}}}
using a "real" db (postgresql) if I try to do this
{{{
objs = [TestModel(number=n) for n in range(11)]
TestModel.objects.bulk_create(objs, batch_size=10)
}}}
I get this error
{{{
/home/bameda/.virtualenvs/taiga/lib/python3.5/site-
packages/django/db/models/manager.py in manager_method(self, *args,
**kwargs)
83 def create_method(name, method):
84 def manager_method(self, *args, **kwargs):
---> 85 return getattr(self.get_queryset(), name)(*args,
**kwargs)
86 manager_method.__name__ = method.__name__
87 manager_method.__doc__ = method.__doc__
/home/bameda/.virtualenvs/taiga/lib/python3.5/site-
packages/django/db/models/query.py in bulk_create(self, objs, batch_size)
450 if objs_without_pk:
451 fields = [f for f in fields if not
isinstance(f, AutoField)]
--> 452 ids = self._batched_insert(objs_without_pk,
fields, batch_size)
453 if
connection.features.can_return_ids_from_bulk_insert:
454 assert len(ids) == len(objs_without_pk)
/home/bameda/.virtualenvs/taiga/lib/python3.5/site-
packages/django/db/models/query.py in _batched_insert(self, objs, fields,
batch_size)
1062 inserted_id = self._insert(item, fields=fields,
using=self.db, return_id=True)
1063 if len(objs) > 1:
-> 1064 inserted_ids.extend(inserted_id)
1065 if len(objs) == 1:
1066 inserted_ids.append(inserted_id)
TypeError: 'int' object is not iterable
}}}
The patch https://github.com/django/django/pull/7433 solved it.
It happens in master and in 1.10.x
--
Ticket URL: <https://code.djangoproject.com/ticket/27385>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.29d005f83c7207ab89f026c159fdec96%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.