Fix None UUID ForeignKey serialization by carltongibson · Pull Request #3915 · encode/django-rest-framework (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here PrimaryKeyRelatedField
calls self.pk_field.to_representation(value.pk)
.
When that's a UUIDField
we hit this block:
if self.uuid_format == 'hex_verbose':
return str(value)
When value
is None
, without the fix, that's equivalent to:
>>> str(None)
'None'
which is the observed output.