From 0a77ff652fa3220fc96ac3e5b5f5d3d40ebe31cb Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 5 Jan 2018 15:39:15 +0100 Subject: [PATCH] fields.get_attribute: return None for FK lookups Ref: https://github.com/encode/django-rest-framework/pull/5708#issuecomment-355569737 --- rest_framework/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index ad710b967..94cd02426 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -98,6 +98,8 @@ def get_attribute(instance, attrs): instance = instance[attr] else: instance = getattr(instance, attr) + if instance is None: + return None except ObjectDoesNotExist: return None if is_simple_callable(instance):