From 889558365bb3947ab77f47207381d5ff6316fa4f Mon Sep 17 00:00:00 2001 From: "J. Paul Reed" Date: Tue, 2 Apr 2013 01:41:31 -0700 Subject: [PATCH] Don't have the ModelSerializer trust deserialized objects to not have redefine bool()ean-ness. If the model we're using the ModelSerializer for has redefined methods that act as a boolean (__bool__ or __len__), it may not return the object even though it is_valid(), and should. --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 1b2b08217..e28bbe81d 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -741,7 +741,7 @@ class ModelSerializer(Serializer): Override the default method to also include model field validation. """ instance = super(ModelSerializer, self).from_native(data, files) - if instance: + if not self._errors: return self.full_clean(instance) def save_object(self, obj, **kwargs):