mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
check instance __getitem__ value first
This commit is contained in:
parent
d7d399f8b6
commit
4d433b6513
|
@ -59,14 +59,16 @@ def get_attribute(instance, attrs):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
# Break out early if we get `None` at any point in a nested lookup.
|
# Break out early if we get `None` at any point in a nested lookup.
|
||||||
return None
|
return None
|
||||||
|
if getattr(instance, '__getitem__', None):
|
||||||
|
try:
|
||||||
|
return instance[attr]
|
||||||
|
except (KeyError, TypeError, AttributeError):
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
instance = getattr(instance, attr)
|
instance = getattr(instance, attr)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return None
|
return None
|
||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
try:
|
|
||||||
return instance[attr]
|
|
||||||
except (KeyError, TypeError, AttributeError):
|
|
||||||
raise exc
|
raise exc
|
||||||
if is_simple_callable(instance):
|
if is_simple_callable(instance):
|
||||||
instance = instance()
|
instance = instance()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user