diff --git a/diode-netbox-plugin/netbox_diode_plugin/api/serializers.py b/diode-netbox-plugin/netbox_diode_plugin/api/serializers.py index b3958afc..9cad0451 100644 --- a/diode-netbox-plugin/netbox_diode_plugin/api/serializers.py +++ b/diode-netbox-plugin/netbox_diode_plugin/api/serializers.py @@ -50,7 +50,7 @@ def get_object(self, instance): return serializer(object_data, context=context, many=True).data[0] -class ChangeSetSerializer(serializers.Serializer): +class ChangeSerialiazer(serializers.Serializer): """ChangeSet Serializer.""" change_id = serializers.UUIDField(required=True) @@ -66,5 +66,5 @@ class ApplyChangeSetRequestSerializer(serializers.Serializer): change_set_id = serializers.UUIDField(required=True) change_set = serializers.ListField( - child=ChangeSetSerializer(), required=True, allow_empty=False + child=ChangeSerialiazer(), required=True, allow_empty=False ) diff --git a/diode-netbox-plugin/netbox_diode_plugin/api/views.py b/diode-netbox-plugin/netbox_diode_plugin/api/views.py index 5de43a31..79bda202 100644 --- a/diode-netbox-plugin/netbox_diode_plugin/api/views.py +++ b/diode-netbox-plugin/netbox_diode_plugin/api/views.py @@ -149,29 +149,31 @@ def post(self, request, *args, **kwargs): serializer_list = [] serializer_errors = [] - serializer = ApplyChangeSetRequestSerializer(data=request.data) + request_serializer = ApplyChangeSetRequestSerializer(data=request.data) change_set_id = self.request.data.get("change_set_id", None) - if not serializer.is_valid(): - for error in serializer.errors: - if isinstance(serializer.errors[error], dict): - for _, error_values in serializer.errors[error].items(): + if not request_serializer.is_valid(): + for field_error_name in request_serializer.errors: + if isinstance(request_serializer.errors[field_error_name], dict): + for _, error_values in request_serializer.errors[ + field_error_name + ].items(): for field_name, field_errors in error_values.items(): serializer_errors.append( {field_name: f"{str(field_errors[0])}"} ) else: errors_dict = { - error: f"{str(field_errors)}" - for field_errors in serializer.errors[error] + field_error_name: f"{str(field_errors)}" + for field_errors in request_serializer.errors[field_error_name] } serializer_errors.append(errors_dict) return self._get_error_response(change_set_id, serializer_errors) - change_set = self.request.data.get("change_set", None) + change_set = request_serializer.data.get("change_set", None) for change in change_set: change_id = change.get("change_id", None)