#21566: Creation of models with ForeignObject fails with bulk_create() function
-------------------------------+--------------------------------------
     Reporter:  rogerhu        |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Uncategorized  |                  Version:  1.6
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Changes (by rhu@…):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 ```
 --- a/django/db/models/query.py
 +++ b/django/db/models/query.py
 @@ -389,7 +389,7 @@ class QuerySet(object):
              return objs
          self._for_write = True
          connection = connections[self.db]
 -        fields = self.model._meta.local_fields
 +        fields = self.model._meta.concrete_fields
          with transaction.commit_on_success_unless_managed(using=self.db):
              if
 (connection.features.can_combine_inserts_with_and_without_auto_increment_pk
                      and self.model._meta.has_auto_field):
 diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
 index 66f57b6..b1502c3 100644
 --- a/tests/foreign_object/tests.py
 +++ b/tests/foreign_object/tests.py
 @@ -4,7 +4,7 @@ from operator import attrgetter
  from .models import (
      Country, Person, Group, Membership, Friendship, Article,
      ArticleTranslation, ArticleTag, ArticleIdea, NewsArticle)
 -from django.test import TestCase
 +from django.test import TestCase, skipUnlessDBFeature
  from django.utils.translation import activate
  from django.core.exceptions import FieldError
  from django import forms
 @@ -380,6 +380,13 @@ class MultiColumnFKTests(TestCase):
                      'active_translation')[0].active_translation.title,
                  "foo")

 +    @skipUnlessDBFeature('has_bulk_insert')
 +    def test_batch_create_foreign_object(self):
 +        self.bob.person_country = self.usa
 +
 +        objs = [Person(name=i, person_country=self.usa) for i in range(0,
 5)]
 +        Person.objects.bulk_create(objs, 10)
 +

 ```

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21566#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 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/065.5abc23f00226ec7610f64d82b8972b75%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to