Commit 2ef74cfa by Carlton Gibson

Bring check for null fk to `BaseSerializer.to_representation`

parent cbb8d8d2
......@@ -778,8 +778,6 @@ class UUIDField(Field):
return data
def to_representation(self, value):
if value is None:
return None
if self.uuid_format == 'hex_verbose':
return str(value)
else:
......
......@@ -464,9 +464,13 @@ class Serializer(BaseSerializer):
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)
......
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