diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index 99c483857..851680d8e 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -251,7 +251,7 @@ class CustomField(ChangeLoggedModel): if self.type == CustomFieldTypeChoices.TYPE_OBJECT: return value.pk if self.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT: - return [obj.pk for obj in value] + return [obj.pk for obj in value] or None return value def deserialize(self, value): diff --git a/netbox/extras/tests/test_forms.py b/netbox/extras/tests/test_forms.py index e8b16d7ab..1ec50b7dd 100644 --- a/netbox/extras/tests/test_forms.py +++ b/netbox/extras/tests/test_forms.py @@ -52,6 +52,13 @@ class CustomFieldModelFormTest(TestCase): ) cf_object.content_types.set([obj_type]) + cf_multiobject = CustomField.objects.create( + name='multiobject', + type=CustomFieldTypeChoices.TYPE_MULTIOBJECT, + object_type=ContentType.objects.get_for_model(Site) + ) + cf_multiobject.content_types.set([obj_type]) + def test_empty_values(self): """ Test that empty custom field values are stored as null