[Patchew-devel] [PATCH] rest: the "data" field of results might not be there

Caio Carrara ccarrara at redhat.com
Wed Nov 28 15:49:03 UTC 2018


On Wed, Nov 28, 2018 at 09:31:25AM +0100, Paolo Bonzini wrote:
> For PATCH requests, for example, the user might be changing other fields
> only.  Check whether the field is there before accessing it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>

Reviewed-by: Caio Carrara <ccarrara at redhat.com>

> ---
>  api/rest.py | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index 573cbf1..041e82d 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -552,9 +552,10 @@ class ResultSerializer(serializers.ModelSerializer):
>          return obj.get_log_url(request)
>  
>      def validate(self, data):
> -        data_serializer_class = self.context['renderer'].result_data_serializer_class
> -        data_serializer_class(data=data['data'],
> -                              context=self.context).is_valid(raise_exception=True)
> +        if 'data' in data:
> +            data_serializer_class = self.context['renderer'].result_data_serializer_class
> +            data_serializer_class(data=data['data'],
> +                                  context=self.context).is_valid(raise_exception=True)
>          return data
>  
>  
> -- 
> 2.19.1
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

-- 
Caio Carrara
Software Engineer, Virt Team - Red Hat
ccarrara at redhat.com




More information about the Patchew-devel mailing list