aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorXavier Ordoquy2014-03-06 21:18:37 +0100
committerXavier Ordoquy2014-03-06 21:18:37 +0100
commit51e6982397cc032d6b3fd66f452713d448eb9084 (patch)
tree38678df89a0c61304a3314439968339f7577b0aa /rest_framework/serializers.py
parentcaf4d36cb3484313a36453a229bfc002a075f811 (diff)
downloaddjango-rest-framework-51e6982397cc032d6b3fd66f452713d448eb9084.tar.bz2
Fixed the validation for optional fields that have a value.
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index c95b0593..5c726dfc 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -881,7 +881,7 @@ class ModelSerializer(Serializer):
except KeyError:
return ModelField(model_field=model_field, **kwargs)
- def get_validation_exclusions(self):
+ def get_validation_exclusions(self, instance=None):
"""
Return a list of field names to exclude from model validation.
"""
@@ -893,7 +893,7 @@ class ModelSerializer(Serializer):
field_name = field.source or field_name
if field_name in exclusions \
and not field.read_only \
- and field.required \
+ and (field.required or hasattr(instance, field_name)) \
and not isinstance(field, Serializer):
exclusions.remove(field_name)
return exclusions
@@ -908,7 +908,7 @@ class ModelSerializer(Serializer):
the full_clean validation checking.
"""
try:
- instance.full_clean(exclude=self.get_validation_exclusions())
+ instance.full_clean(exclude=self.get_validation_exclusions(instance))
except ValidationError as err:
self._errors = err.message_dict
return None