Skip to content

Commit 8895583

Browse files
committed
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.
1 parent 5ed7032 commit 8895583

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rest_framework/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def from_native(self, data, files):
741741
Override the default method to also include model field validation.
742742
"""
743743
instance = super(ModelSerializer, self).from_native(data, files)
744-
if instance:
744+
if not self._errors:
745745
return self.full_clean(instance)
746746

747747
def save_object(self, obj, **kwargs):

0 commit comments

Comments
 (0)