From b45a4acf6f29025f28baf524809f34a14b7ccde7 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 10 Sep 2011 21:46:59 +0000 Subject: [PATCH] Ensure bulk_create returns the right value if the argument is an empty list. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16792 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 2 +- tests/regressiontests/bulk_create/tests.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index dbd37b1822..0e1a1b31b4 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -372,7 +372,7 @@ class QuerySet(object): if self.model._meta.parents: raise ValueError("Can't bulk create an inherited model") if not objs: - return + return objs self._for_write = True connection = connections[self.db] fields = self.model._meta.local_fields diff --git a/tests/regressiontests/bulk_create/tests.py b/tests/regressiontests/bulk_create/tests.py index d7d19a54aa..18383b52ed 100644 --- a/tests/regressiontests/bulk_create/tests.py +++ b/tests/regressiontests/bulk_create/tests.py @@ -23,6 +23,10 @@ class BulkCreateTests(TestCase): "United States of America", "The Netherlands", "Germany", "Czech Republic" ], attrgetter("name")) + created = Country.objects.bulk_create([]) + self.assertEqual(created, []) + self.assertEqual(Country.objects.count(), 4) + @skipUnlessDBFeature("has_bulk_insert") def test_efficiency(self): with self.assertNumQueries(1):