mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Support None if initial part of dotted lookup returns None. Closes #1223.
This commit is contained in:
parent
c70242c35b
commit
26b6180f50
|
@ -57,6 +57,9 @@ def get_attribute(instance, attrs):
|
|||
Also accepts either attribute lookup on objects or dictionary lookups.
|
||||
"""
|
||||
for attr in attrs:
|
||||
if instance is None:
|
||||
# Break out early if we get `None` at any point in a nested lookup.
|
||||
return None
|
||||
try:
|
||||
instance = getattr(instance, attr)
|
||||
except ObjectDoesNotExist:
|
||||
|
|
Loading…
Reference in New Issue
Block a user