From 5c680c36e435ffa29ba6ed5f439d22ea4e849c67 Mon Sep 17 00:00:00 2001 From: Mark Aaron Shirley Date: Wed, 19 Dec 2012 09:26:40 -0800 Subject: [PATCH] Check if RelatedField is required. --- rest_framework/fields.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 2060e3e70..b0dfdce8c 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -351,6 +351,11 @@ 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: + return + value = data.get(field_name) if value in (None, '') and not self.null: