From 296ebc5c274f2dfff46a4ac916851e8c73b8a21e Mon Sep 17 00:00:00 2001 From: 5505005 <964309172@qq.com> Date: Tue, 26 Mar 2019 22:06:01 +0800 Subject: [PATCH] When i using the source function of serializers there was a problem, the source of a foreign key field will give me an error named incorrectly and not match any attribute, the foreign key is correct, but I just haven't add data, it is clearly wrong, so I modified the code, let it out key correctly and without adding data return None --- rest_framework/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index c8f65db0e..adec05eec 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -101,6 +101,8 @@ def get_attribute(instance, attrs): instance = getattr(instance, attr) except ObjectDoesNotExist: return None + if instance == None: + return None if is_simple_callable(instance): try: instance = instance()