From fcbee119e2176c7ee91804c36d79405c5b7d1c5f Mon Sep 17 00:00:00 2001 From: Jakub Dubec Date: Thu, 19 Dec 2019 14:49:36 +0100 Subject: [PATCH] =?UTF-8?q?Skip=20processing=20of=20the=20FormField=20if?= =?UTF-8?q?=20value=20is=20not=20required=20and=20empty=20=F0=9F=8C=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ django_request_formatter/__version__.py | 2 +- django_request_formatter/fields.py | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1f0c7a..e510d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.2 : 19.12.2019 + +- **Fix**: Skip processing of the `FormField` if value is not required and empty + ## 0.5.1 : 19.12.2019 - **Fix**: Process `EnumField` even if it's not marked as required diff --git a/django_request_formatter/__version__.py b/django_request_formatter/__version__.py index 93b60a1..45869b6 100644 --- a/django_request_formatter/__version__.py +++ b/django_request_formatter/__version__.py @@ -1 +1 @@ -__version__ = '0.5.1' +__version__ = '0.5.2' diff --git a/django_request_formatter/fields.py b/django_request_formatter/fields.py index 4c96079..e119331 100644 --- a/django_request_formatter/fields.py +++ b/django_request_formatter/fields.py @@ -57,7 +57,10 @@ def __init__(self, form: typing.Type, **kwargs): def form(self): return self._form - def to_python(self, value) -> dict: + def to_python(self, value) -> typing.Union[typing.Dict, None]: + if not value: + return None + form = self._form(value) if form.is_valid(): return form.cleaned_data