1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #13849: Fix label resolution during serialization for removed field choices (#13867)

* Fixes #13849: Fix label resolution during serialization for removed field choices

* Cleanup
This commit is contained in:
Jeremy Stretch
2023-09-26 12:06:47 -04:00
committed by GitHub
parent 099aff5ebe
commit 3cb41bbe3a

View File

@ -46,12 +46,13 @@ class ChoiceField(serializers.Field):
return super().validate_empty_values(data)
def to_representation(self, obj):
if obj == '':
return None
return {
'value': obj,
'label': self._choices[obj],
}
if obj != '':
# Use an empty string in place of the choice label if it cannot be resolved (i.e. because a previously
# configured choice has been removed from FIELD_CHOICES).
return {
'value': obj,
'label': self._choices.get(obj, ''),
}
def to_internal_value(self, data):
if data == '':