Fixed #21566 -- Fixed AttributeError when using bulk_create with ForeignObject.
This commit is contained in:
parent
38e24d680d
commit
bbc73e6a12
|
@ -389,7 +389,7 @@ class QuerySet(object):
|
||||||
return objs
|
return objs
|
||||||
self._for_write = True
|
self._for_write = True
|
||||||
connection = connections[self.db]
|
connection = connections[self.db]
|
||||||
fields = self.model._meta.local_fields
|
fields = self.model._meta.local_concrete_fields
|
||||||
with transaction.commit_on_success_unless_managed(using=self.db):
|
with transaction.commit_on_success_unless_managed(using=self.db):
|
||||||
if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk
|
if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk
|
||||||
and self.model._meta.has_auto_field):
|
and self.model._meta.has_auto_field):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from operator import attrgetter
|
||||||
from .models import (
|
from .models import (
|
||||||
Country, Person, Group, Membership, Friendship, Article,
|
Country, Person, Group, Membership, Friendship, Article,
|
||||||
ArticleTranslation, ArticleTag, ArticleIdea, NewsArticle)
|
ArticleTranslation, ArticleTag, ArticleIdea, NewsArticle)
|
||||||
from django.test import TestCase
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.utils.translation import activate
|
from django.utils.translation import activate
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -380,6 +380,12 @@ class MultiColumnFKTests(TestCase):
|
||||||
'active_translation')[0].active_translation.title,
|
'active_translation')[0].active_translation.title,
|
||||||
"foo")
|
"foo")
|
||||||
|
|
||||||
|
@skipUnlessDBFeature('has_bulk_insert')
|
||||||
|
def test_batch_create_foreign_object(self):
|
||||||
|
""" See: https://code.djangoproject.com/ticket/21566 """
|
||||||
|
objs = [Person(name="abcd_%s" % i, person_country=self.usa) for i in range(0, 5)]
|
||||||
|
Person.objects.bulk_create(objs, 10)
|
||||||
|
|
||||||
|
|
||||||
class FormsTests(TestCase):
|
class FormsTests(TestCase):
|
||||||
# ForeignObjects should not have any form fields, currently the user needs
|
# ForeignObjects should not have any form fields, currently the user needs
|
||||||
|
|
Loading…
Reference in New Issue