mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #27385 -- Fixed QuerySet.bulk_create() on PostgreSQL when the number of objects is a multiple plus one of batch_size.
This commit is contained in:
parent
a9d1d95284
commit
b3bd3aa07c
3 changed files with 16 additions and 6 deletions
|
@ -171,11 +171,18 @@ class BulkCreateTests(TestCase):
|
|||
|
||||
def test_explicit_batch_size(self):
|
||||
objs = [TwoFields(f1=i, f2=i) for i in range(0, 4)]
|
||||
TwoFields.objects.bulk_create(objs, 2)
|
||||
self.assertEqual(TwoFields.objects.count(), len(objs))
|
||||
num_objs = len(objs)
|
||||
TwoFields.objects.bulk_create(objs, batch_size=1)
|
||||
self.assertEqual(TwoFields.objects.count(), num_objs)
|
||||
TwoFields.objects.all().delete()
|
||||
TwoFields.objects.bulk_create(objs, len(objs))
|
||||
self.assertEqual(TwoFields.objects.count(), len(objs))
|
||||
TwoFields.objects.bulk_create(objs, batch_size=2)
|
||||
self.assertEqual(TwoFields.objects.count(), num_objs)
|
||||
TwoFields.objects.all().delete()
|
||||
TwoFields.objects.bulk_create(objs, batch_size=3)
|
||||
self.assertEqual(TwoFields.objects.count(), num_objs)
|
||||
TwoFields.objects.all().delete()
|
||||
TwoFields.objects.bulk_create(objs, batch_size=num_objs)
|
||||
self.assertEqual(TwoFields.objects.count(), num_objs)
|
||||
|
||||
def test_empty_model(self):
|
||||
NoFields.objects.bulk_create([NoFields() for i in range(2)])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue