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

Paolo Bonzini posted 1 patch 2 weeks ago
Failed in applying to current master (apply log)
api/rest.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

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

Posted by Paolo Bonzini 2 weeks ago
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@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@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

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

Posted by Caio Carrara 1 week ago
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@redhat.com>

Reviewed-by: Caio Carrara <ccarrara@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@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

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

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel