Commit 26b6180f by Tom Christie

Support None if initial part of dotted lookup returns None. Closes #1223.

parent c70242c3
...@@ -57,6 +57,9 @@ def get_attribute(instance, attrs): ...@@ -57,6 +57,9 @@ def get_attribute(instance, attrs):
Also accepts either attribute lookup on objects or dictionary lookups. Also accepts either attribute lookup on objects or dictionary lookups.
""" """
for attr in attrs: 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: try:
instance = getattr(instance, attr) instance = getattr(instance, attr)
except ObjectDoesNotExist: except ObjectDoesNotExist:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment