Arthur 1 неделя назад
Родитель
Сommit
f6cf81ea5a
2 измененных файлов с 11 добавлено и 5 удалено
  1. 10 0
      netbox/extras/api/serializers_/scripts.py
  2. 1 5
      netbox/extras/api/views.py

+ 10 - 0
netbox/extras/api/serializers_/scripts.py

@@ -188,6 +188,16 @@ class ScriptInputSerializer(serializers.Serializer):
         if script and script.python_class:
         if script and script.python_class:
             self.fields['notifications'].default = script.python_class.notifications_default
             self.fields['notifications'].default = script.python_class.notifications_default
 
 
+    def validate_data(self, value):
+        """
+        Validates that the script input is an object mapping variable names to values.
+        """
+        if not isinstance(value, dict):
+            raise serializers.ValidationError(
+                _('Invalid data payload; expected an object mapping variable names to values.')
+            )
+        return value
+
     def validate_schedule_at(self, value):
     def validate_schedule_at(self, value):
         """
         """
         Validates the specified schedule time for a script execution.
         Validates the specified schedule time for a script execution.

+ 1 - 5
netbox/extras/api/views.py

@@ -409,11 +409,7 @@ class ScriptViewSet(ListModelMixin, RetrieveModelMixin, BaseViewSet):
 
 
         validated = input_serializer.validated_data
         validated = input_serializer.validated_data
 
 
-        payload = validated.get('data')
-        if not isinstance(payload, dict):
-            raise ValidationError(
-                {'data': _('Invalid data payload; expected an object mapping variable names to values.')}
-            )
+        payload = validated['data']
 
 
         # Guaranteed non-None by the is_executable check above
         # Guaranteed non-None by the is_executable check above
         script_class = script.python_class
         script_class = script.python_class