Fix One field that is required=False, allow_null=True and not provided. to_representation should not explicitly set it to None

This commit is contained in:
liyilun 2024-07-08 19:11:48 +08:00
parent ccfe0a9637
commit b0ca35ea55

View File

@ -450,10 +450,10 @@ class Field:
except (KeyError, AttributeError) as exc:
if self.default is not empty:
return self.get_default()
if self.allow_null:
return None
if not self.required:
raise SkipField()
if self.allow_null:
return None
msg = (
'Got {exc_type} when attempting to get a value for field '
'`{field}` on serializer `{serializer}`.\nThe serializer '