From 4a51ba228b2c416a115aee3bc034683eb02482c3 Mon Sep 17 00:00:00 2001 From: Illia Volochii Date: Tue, 27 Dec 2016 16:42:17 +0200 Subject: [PATCH] Fixed #27642 -- Made forms.utils.flatatt() omit 'None' values from attrs. --- django/forms/utils.py | 2 +- tests/forms_tests/tests/test_utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/django/forms/utils.py b/django/forms/utils.py index dc4df86058..88086b2c64 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -40,7 +40,7 @@ def flatatt(attrs): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) - else: + elif value is not None: key_value_attrs.append((attr, value)) return ( diff --git a/tests/forms_tests/tests/test_utils.py b/tests/forms_tests/tests/test_utils.py index a6a2d81b9f..f95c956322 100644 --- a/tests/forms_tests/tests/test_utils.py +++ b/tests/forms_tests/tests/test_utils.py @@ -34,6 +34,7 @@ class FormsUtilsTestCase(SimpleTestCase): flatatt({'class': "news", 'title': "Read this", 'required': False}), ' class="news" title="Read this"' ) + self.assertEqual(flatatt({'class': None}), '') self.assertEqual(flatatt({}), '') def test_flatatt_no_side_effects(self):