{{{
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.
* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Ready for checkin
Old description:
> With the model
>
New description:
With the model:
{{{
from django.db import models
class TestModel(models.Model):
number = models.IntegerField()
}}}
If I try to do this on PostgreSQL:
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27385#comment:1>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"b3bd3aa07c026239dd39d1a37498dfd0a2f09caf" b3bd3aa]:
{{{
#!CommitTicketReference repository=""
revision="b3bd3aa07c026239dd39d1a37498dfd0a2f09caf"
Fixed #27385 -- Fixed QuerySet.bulk_create() on PostgreSQL when the number
of objects is a multiple plus one of batch_size.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27385#comment:2>
Comment (by Tim Graham <timograham@…>):
In [changeset:"736f7e7ed7d04cfb9032636b5b65cba26ec7d6db" 736f7e7e]:
{{{
#!CommitTicketReference repository=""
revision="736f7e7ed7d04cfb9032636b5b65cba26ec7d6db"
[1.10.x] Fixed #27385 -- Fixed QuerySet.bulk_create() on PostgreSQL when
the number of objects is a multiple plus one of batch_size.
Backport of b3bd3aa07c026239dd39d1a37498dfd0a2f09caf from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27385#comment:3>