MCPcopy
hub / github.com/django/django / test_bulk_insert_nullable_fields

Method test_bulk_insert_nullable_fields

tests/bulk_create/tests.py:328–351  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

326
327 @skipUnlessDBFeature("has_bulk_insert")
328 def test_bulk_insert_nullable_fields(self):
329 fk_to_auto_fields = {
330 "auto_field": NoFields.objects.create(),
331 "small_auto_field": SmallAutoFieldModel.objects.create(),
332 "big_auto_field": BigAutoFieldModel.objects.create(),
333 }
334 # NULL can be mixed with other values in nullable fields
335 nullable_fields = [
336 field for field in NullableFields._meta.get_fields() if field.name != "id"
337 ]
338 NullableFields.objects.bulk_create(
339 [
340 NullableFields(**{**fk_to_auto_fields, field.name: None})
341 for field in nullable_fields
342 ]
343 )
344 self.assertEqual(NullableFields.objects.count(), len(nullable_fields))
345 for field in nullable_fields:
346 with self.subTest(field=field):
347 field_value = "" if isinstance(field, FileField) else None
348 self.assertEqual(
349 NullableFields.objects.filter(**{field.name: field_value}).count(),
350 1,
351 )
352
353 @skipUnlessDBFeature("can_return_rows_from_bulk_insert")
354 def test_set_pk_and_insert_single_item(self):

Callers

nothing calls this directly

Calls 6

NullableFieldsClass · 0.85
bulk_createMethod · 0.80
createMethod · 0.45
get_fieldsMethod · 0.45
countMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected