From bdb73d558891192c96368d5ca2266327302dba54 Mon Sep 17 00:00:00 2001 From: Evan Heidtmann Date: Thu, 26 Feb 2015 09:00:51 -0800 Subject: [PATCH] Avoid swallowing exceptions thrown in callable attributes --- rest_framework/fields.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index a5348922a..01e7c78c8 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -71,7 +71,11 @@ def get_attribute(instance, attrs): except ObjectDoesNotExist: return None if is_simple_callable(instance): - instance = instance() + try: + instance = instance() + except (AttributeError, KeyError) as exc: + raise ValueError('Exception raised in callable attribute "{0}"; original exception was: {1}'.format(attr, exc)) + return instance