1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #22669 -- Fixed QuerySet.bulk_create() with empty model fields on Oracle.

This commit is contained in:
Mikhail Nacharov
2017-02-07 09:49:31 +05:00
committed by Tim Graham
parent 965f678a39
commit c4e2fc5d98
4 changed files with 88 additions and 8 deletions

View File

@@ -1,15 +1,16 @@
from operator import attrgetter
from django.db import connection
from django.db.models import Value
from django.db.models import FileField, Value
from django.db.models.functions import Lower
from django.test import (
TestCase, override_settings, skipIfDBFeature, skipUnlessDBFeature,
)
from .models import (
Country, NoFields, Pizzeria, ProxyCountry, ProxyMultiCountry,
ProxyMultiProxyCountry, ProxyProxyCountry, Restaurant, State, TwoFields,
Country, NoFields, NullableFields, Pizzeria, ProxyCountry,
ProxyMultiCountry, ProxyMultiProxyCountry, ProxyProxyCountry, Restaurant,
State, TwoFields,
)
@@ -204,6 +205,19 @@ class BulkCreateTests(TestCase):
bbb = Restaurant.objects.filter(name="betty's beetroot bar")
self.assertEqual(bbb.count(), 1)
@skipUnlessDBFeature('has_bulk_insert')
def test_bulk_insert_nullable_fields(self):
# NULL can be mixed with other values in nullable fields
nullable_fields = [field for field in NullableFields._meta.get_fields() if field.name != 'id']
NullableFields.objects.bulk_create([
NullableFields(**{field.name: None}) for field in nullable_fields
])
self.assertEqual(NullableFields.objects.count(), len(nullable_fields))
for field in nullable_fields:
with self.subTest(field=field):
field_value = '' if isinstance(field, FileField) else None
self.assertEqual(NullableFields.objects.filter(**{field.name: field_value}).count(), 1)
@skipUnlessDBFeature('can_return_ids_from_bulk_insert')
def test_set_pk_and_insert_single_item(self):
with self.assertNumQueries(1):