Re: [Django] #27385: Error in QuerySet.bulk_create() on PostgreSQL when objs length is a multiple plus one of batch_size

2016-10-25 Thread Django
#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:  closed
Component:  Database layer   |  Version:  1.10
  (models, ORM)  |
 Severity:  Release blocker  |   Resolution:  fixed
 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
-+-

Comment (by Tim Graham ):

 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: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.62b494eca0162aa4bd5deb66c4c93def%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27385: Error in QuerySet.bulk_create() on PostgreSQL when objs length is a multiple plus one of batch_size

2016-10-25 Thread Django
#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:  closed
Component:  Database layer   |  Version:  1.10
  (models, ORM)  |
 Severity:  Release blocker  |   Resolution:  fixed
 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 ):

 * 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: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.f6c8b6897e280619367f07c2e17b009b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27385: Error in QuerySet.bulk_create() on PostgreSQL when objs length is a multiple plus one of batch_size (was: Error in bulk_create() when objs length is a multiple plus one of batch_s

2016-10-25 Thread Django
#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