aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorMark Aaron Shirley2013-01-04 21:11:03 +0100
committerMark Aaron Shirley2013-01-04 21:11:03 +0100
commit213981cef394c6f7603c24b9a51096ffb56f6024 (patch)
tree356de336d49fc2552ae819009a4f0de572e8525d /rest_framework/serializers.py
parentad671022e1a43f91e0285f53bab64b7e33395eb3 (diff)
downloaddjango-rest-framework-213981cef394c6f7603c24b9a51096ffb56f6024.tar.bz2
Handle ObjectDoesNotExist exceptions when serializing null reverse one-to-one
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index bd54db4c..3391a262 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -293,15 +293,18 @@ class BaseSerializer(Field):
Override default so that we can apply ModelSerializer as a nested
field to relationships.
"""
- if self.source:
- for component in self.source.split('.'):
- obj = getattr(obj, component)
+ try:
+ if self.source:
+ for component in self.source.split('.'):
+ obj = getattr(obj, component)
+ if is_simple_callable(obj):
+ obj = obj()
+ else:
+ obj = getattr(obj, field_name)
if is_simple_callable(obj):
obj = obj()
- else:
- obj = getattr(obj, field_name)
- if is_simple_callable(obj):
- obj = value()
+ except ObjectDoesNotExist:
+ return None
# If the object has an "all" method, assume it's a relationship
if is_simple_callable(getattr(obj, 'all', None)):