Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Bring check for null fk to BaseSerializer.to_representation
  • Loading branch information
carltongibson committed Mar 13, 2016
commit 2ef74cfa61d6f52a2a5c32151a052488d5d7e9e2
2 changes: 0 additions & 2 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,6 @@ def to_internal_value(self, data):
return data

def to_representation(self, value):
if value is None:
return None
if self.uuid_format == 'hex_verbose':
return str(value)
else:
Expand Down
10 changes: 7 additions & 3 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,13 @@ def to_representation(self, instance):
except SkipField:
continue

if attribute is None:
# We skip `to_representation` for `None` values so that
# fields do not have to explicitly deal with that case.
# We skip `to_representation` for `None` values so that fields do
# not have to explicitly deal with that case.
#
# For related fields with `use_pk_only_optimization` we need to
# resolve the pk value.
check_for_none = attribute.pk if isinstance(attribute, PKOnlyObject) else attribute
if check_for_none is None:
ret[field.field_name] = None
else:
ret[field.field_name] = field.to_representation(attribute)
Expand Down