diff options
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 18 | ||||
| -rw-r--r-- | rest_framework/serializers.py | 2 | 
2 files changed, 19 insertions, 1 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 25122e14..205efd2f 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -274,7 +274,23 @@ class Field(object):          Given the *outgoing* object instance, return the primitive value          that should be used for this field.          """ -        return get_attribute(instance, self.source_attrs) +        try: +            return get_attribute(instance, self.source_attrs) +        except (KeyError, AttributeError) as exc: +            msg = ( +                'Got {exc_type} when attempting to get a value for field ' +                '`{field}` on serializer `{serializer}`.\nThe serializer ' +                'field might be named incorrectly and not match ' +                'any attribute or key on the `{instance}` instance.\n' +                'Original exception text was: {exc}.'.format( +                    exc_type=type(exc).__name__, +                    field=self.field_name, +                    serializer=self.parent.__class__.__name__, +                    instance=instance.__class__.__name__, +                    exc=exc +                ) +            ) +            raise type(exc)(msg)      def get_default(self):          """ diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 9226895e..5adbca3b 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -611,6 +611,7 @@ def raise_errors_on_nested_writes(method_name, serializer, validated_data):      #     profile = ProfileSerializer()      assert not any(          isinstance(field, BaseSerializer) and (key in validated_data) +        and isinstance(validated_data[key], (list, dict))          for key, field in serializer.fields.items()      ), (          'The `.{method_name}()` method does not support writable nested' @@ -630,6 +631,7 @@ def raise_errors_on_nested_writes(method_name, serializer, validated_data):      #     address = serializer.CharField('profile.address')      assert not any(          '.' in field.source and (key in validated_data) +        and isinstance(validated_data[key], (list, dict))          for key, field in serializer.fields.items()      ), (          'The `.{method_name}()` method does not support writable dotted-source ' | 
