Explorar o código

Fixes #2334: TypeError raised when WritableNestedSerializer receives a non-integer value

Jeremy Stretch %!s(int64=7) %!d(string=hai) anos
pai
achega
a2ff21fab9
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      netbox/utilities/api.py

+ 3 - 1
netbox/utilities/api.py

@@ -170,7 +170,9 @@ class WritableNestedSerializer(ModelSerializer):
         if data is None:
             return None
         try:
-            return self.Meta.model.objects.get(pk=data)
+            return self.Meta.model.objects.get(pk=int(data))
+        except (TypeError, ValueError):
+            raise ValidationError("Primary key must be an integer")
         except ObjectDoesNotExist:
             raise ValidationError("Invalid ID")