From c6bc7ffb28e06bdfbb31cab131c31e7634fb95af Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Fri, 20 Oct 2017 10:39:40 -0400 Subject: [PATCH] Field 'allow_null' provides serialization default --- rest_framework/fields.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 48cd74513..ab8f2eb44 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -311,10 +311,6 @@ class Field(object): self._creation_counter = Field._creation_counter Field._creation_counter += 1 - # If `default` is unset, then use `None` when allow_null is `True`. - if default is empty and allow_null: - default = None - # If `required` is unset, then use `True` unless a default is provided. if required is None: required = default is empty and not read_only @@ -446,6 +442,8 @@ class Field(object): 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() msg = (