diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1059df918..dd90c3f86 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -351,13 +351,13 @@ class RelatedField(WritableField): if self.read_only: return - if field_name not in data and self.required: - raise ValidationError(self.error_messages['required']) - elif field_name not in data: + try: + value = data[field_name] + except KeyError: + if self.required: + raise ValidationError(self.error_messages['required']) return - value = data.get(field_name) - if value in (None, '') and not self.null: raise ValidationError('Value may not be null') elif value in (None, '') and self.null: