[Patchew-devel] [PATCH] rest: the "data" field of results might not be there
Paolo Bonzini
pbonzini at redhat.com
Wed Nov 28 08:31:25 UTC 2018
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>
---
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
More information about the Patchew-devel
mailing list