Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions netbox/netbox/api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def validate_empty_values(self, data):
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 == '':
Expand Down
Loading