From f98d487931e7b15580b7fbb8776ae11094ebcd66 Mon Sep 17 00:00:00 2001 From: Jarrod Baumann Date: Wed, 5 Nov 2014 00:41:50 -0600 Subject: [PATCH] updated patch with additional checks where request method may not be populated --- rest_framework/serializers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index c56508c54..3156c9fbb 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -592,7 +592,8 @@ class ModelSerializer(Serializer): # Note that we make sure to check `unique_together` both on the # base model class, but also on any parent classes. for parent_class in [model_class] + list(model_class._meta.parents.keys()): - if self.context.get('request').method != 'PATCH': + http_method = getattr(self.context.get('request'), 'method', None) + if http_method and http_method != 'PATCH': for unique_together in parent_class._meta.unique_together: if field_names.issuperset(set(unique_together)): validator = UniqueTogetherValidator(