File tree 1 file changed +5
-6
lines changed
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 15
15
from rest_framework .exceptions import ValidationError
16
16
from rest_framework .settings import api_settings
17
17
from rest_framework .utils import html , representation , humanize_datetime
18
+ import collections
18
19
import copy
19
20
import datetime
20
21
import decimal
@@ -60,14 +61,12 @@ def get_attribute(instance, attrs):
60
61
# Break out early if we get `None` at any point in a nested lookup.
61
62
return None
62
63
try :
63
- instance = getattr (instance , attr )
64
+ if isinstance (instance , collections .Mapping ):
65
+ instance = instance [attr ]
66
+ else :
67
+ instance = getattr (instance , attr )
64
68
except ObjectDoesNotExist :
65
69
return None
66
- except AttributeError as exc :
67
- try :
68
- return instance [attr ]
69
- except (KeyError , TypeError , AttributeError ):
70
- raise exc
71
70
if is_simple_callable (instance ):
72
71
instance = instance ()
73
72
return instance
You can’t perform that action at this time.
0 commit comments