From f83ed19d22250eb646c9d77ccb1614a78d134e75 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 9 Oct 2014 16:29:34 +0100 Subject: [PATCH] Checks and repr on BoundField --- rest_framework/serializers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 1c006990b..3bd7b17b7 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -180,6 +180,7 @@ class BoundField(object): yield self[field.field_name] def __getitem__(self, key): + assert hasattr(self, 'fields'), '"%s" is not a nested field. Cannot perform indexing.' % self.name field = self.fields[key] value = self.value.get(key) if self.value else None error = self.errors.get(key) if self.errors else None @@ -189,6 +190,9 @@ class BoundField(object): def _proxy_class(self): return self._field.__class__ + def __repr__(self): + return '<%s value=%s errors=%s>' % (self.__class__.__name__, self.value, self.errors) + class BindingDict(object): """