diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index aa99e739f..29593c9cb 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -18,6 +18,7 @@ * [#11077](https://github.com/netbox-community/netbox/issues/11077) - Honor configured date format when displaying date custom field values in tables * [#11087](https://github.com/netbox-community/netbox/issues/11087) - Fix background color of bottom banner content * [#11101](https://github.com/netbox-community/netbox/issues/11101) - Correct circuits count under site view +* [#11109](https://github.com/netbox-community/netbox/issues/11109) - Fix nullification of custom object & multi-object fields via REST API * [#11128](https://github.com/netbox-community/netbox/issues/11128) - Disable ordering changelog table by object to avoid exception * [#11142](https://github.com/netbox-community/netbox/issues/11142) - Correct available choices for status under IP range filter form * [#11168](https://github.com/netbox-community/netbox/issues/11168) - Honor `RQ_DEFAULT_TIMEOUT` config parameter when using Redis Sentinel diff --git a/netbox/extras/api/customfields.py b/netbox/extras/api/customfields.py index 17e6f77c5..d16fc0daf 100644 --- a/netbox/extras/api/customfields.py +++ b/netbox/extras/api/customfields.py @@ -72,7 +72,7 @@ class CustomFieldsDataField(Field): # Serialize object and multi-object values for cf in self._get_custom_fields(): - if cf.name in data and cf.type in ( + if cf.name in data and data[cf.name] not in (None, []) and cf.type in ( CustomFieldTypeChoices.TYPE_OBJECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT ): diff --git a/netbox/extras/tests/test_customfields.py b/netbox/extras/tests/test_customfields.py index a023dd7fb..2a03e05d6 100644 --- a/netbox/extras/tests/test_customfields.py +++ b/netbox/extras/tests/test_customfields.py @@ -854,6 +854,18 @@ class CustomFieldAPITest(APITestCase): [vlans[1].pk, vlans[2].pk] ) + # Clear related objects + data = { + 'custom_fields': { + 'object_field': None, + 'multiobject_field': [], + }, + } + response = self.client.patch(url, data, format='json', **self.header) + self.assertHttpStatus(response, status.HTTP_200_OK) + self.assertIsNone(response.data['custom_fields']['object_field']) + self.assertListEqual(response.data['custom_fields']['multiobject_field'], []) + def test_minimum_maximum_values_validation(self): site2 = Site.objects.get(name='Site 2') url = reverse('dcim-api:site-detail', kwargs={'pk': site2.pk})