move check to serializer

This commit is contained in:
Arthur 2026-09-04 14:59:38 -07:00
parent 2ac85a3511
commit f6cf81ea5a
2 changed files with 11 additions and 5 deletions

View File

@ -188,6 +188,16 @@ class ScriptInputSerializer(serializers.Serializer):
if script and script.python_class:
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):
"""
Validates the specified schedule time for a script execution.

View File

@ -409,11 +409,7 @@ class ScriptViewSet(ListModelMixin, RetrieveModelMixin, BaseViewSet):
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
script_class = script.python_class