Skip to content

Commit

Permalink
Fixes #1297: Allow passing custom field choice selection PKs as strin…
Browse files Browse the repository at this point in the history
…g-quoted integers
  • Loading branch information
jeremystretch committed Jul 5, 2017
1 parent 25ee796 commit 1d4a416
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions netbox/extras/api/customfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def to_internal_value(self, data):

# Validate selected choice
if cf.type == CF_TYPE_SELECT:
try:
value = int(value)
except ValueError:
raise ValidationError("{}: Choice selections must be passed as integers.".format(field_name))
valid_choices = [c.pk for c in cf.choices.all()]
if value not in valid_choices:
raise ValidationError("Invalid choice for field {}: {}".format(field_name, value))
Expand Down

0 comments on commit 1d4a416

Please sign in to comment.