api/rest.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
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
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
© 2016 - 2023 Red Hat, Inc.