From 1d4a416100dd3fa6e6a3b2e54c66ab51e38d92c6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 5 Jul 2017 11:00:43 -0400 Subject: [PATCH] Fixes #1297: Allow passing custom field choice selection PKs as string-quoted integers --- netbox/extras/api/customfields.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netbox/extras/api/customfields.py b/netbox/extras/api/customfields.py index da15ce1aa..5a1878b77 100644 --- a/netbox/extras/api/customfields.py +++ b/netbox/extras/api/customfields.py @@ -49,6 +49,10 @@ class CustomFieldsSerializer(serializers.BaseSerializer): # 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))