diff options
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 9 | 
1 files changed, 8 insertions, 1 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 13ea6dde..c0f93816 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -71,7 +71,14 @@ def get_attribute(instance, attrs):          except ObjectDoesNotExist:              return None          if is_simple_callable(instance): -            instance = instance() +            try: +                instance = instance() +            except (AttributeError, KeyError) as exc: +                # If we raised an Attribute or KeyError here it'd get treated +                # as an omitted field in `Field.get_attribute()`. Instead we +                # raise a ValueError to ensure the exception is not masked. +                raise ValueError('Exception raised in callable attribute "{0}"; original exception was: {1}'.format(attr, exc)) +      return instance | 
