diff options
| author | Xavier Ordoquy | 2014-03-06 21:18:37 +0100 |
|---|---|---|
| committer | Xavier Ordoquy | 2014-03-06 21:18:37 +0100 |
| commit | 51e6982397cc032d6b3fd66f452713d448eb9084 (patch) | |
| tree | 38678df89a0c61304a3314439968339f7577b0aa /rest_framework/serializers.py | |
| parent | caf4d36cb3484313a36453a229bfc002a075f811 (diff) | |
| download | django-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.py | 6 |
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 |
