#27385: Error in QuerySet.bulk_create() on PostgreSQL when objs length is a
multiple plus one of batch_size
-------------------------------------+-------------------------------------
     Reporter:  David Barragán       |                    Owner:  nobody
  Merino                             |
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.10
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * severity:  Normal => Release blocker
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0
 * stage:  Unreviewed => Ready for checkin


Old description:

> 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

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:
 {{{
 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#comment:1>
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/064.c1b5a3f66f10f0bb159478a8ce66f049%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to