소스 검색

Fixes #1297: Allow passing custom field choice selection PKs as string-quoted integers

Jeremy Stretch 9 년 전
부모
커밋
1d4a416100
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      netbox/extras/api/customfields.py

+ 4 - 0
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))