Skip to content

Commit

Permalink
Improve field lookup behavior for dicts/mappings. Closes #2244. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Dec 10, 2014
1 parent 76956be commit 81d0b74
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rest_framework.exceptions import ValidationError
from rest_framework.settings import api_settings
from rest_framework.utils import html, representation, humanize_datetime
import collections
import copy
import datetime
import decimal
Expand Down Expand Up @@ -60,14 +61,12 @@ def get_attribute(instance, attrs):
# Break out early if we get `None` at any point in a nested lookup.
return None
try:
instance = getattr(instance, attr)
if isinstance(instance, collections.Mapping):
instance = instance[attr]
else:
instance = getattr(instance, attr)
except ObjectDoesNotExist:
return None
except AttributeError as exc:
try:
return instance[attr]
except (KeyError, TypeError, AttributeError):
raise exc
if is_simple_callable(instance):
instance = instance()
return instance
Expand Down

0 comments on commit 81d0b74

Please sign in to comment.