From 1c4a9bd9ad1a8e61817c6aa2b0d8d0ad2c080047 Mon Sep 17 00:00:00 2001 From: Marc Tamlyn Date: Thu, 8 Aug 2013 14:27:48 +0100 Subject: [PATCH] Revert change to the default Form.clean() This means it doesn't break for people who are doing `cleaned_data = super(FooForm, self).clean()`. --- django/forms/forms.py | 2 +- docs/releases/1.7.txt | 3 +-- tests/forms_tests/tests/test_extra.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index 97ee72e98ed..c2b700ce778 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -318,7 +318,7 @@ class BaseForm(object): not be associated with a particular field; it will have a special-case association with the field named '__all__'. """ - pass + return self.cleaned_data def has_changed(self): """ diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index 6bf13834d2c..26a0beeece7 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -129,8 +129,7 @@ Minor features * The :meth:`~django.forms.Form.clean` method on a form no longer needs to return ``self.cleaned_data``. If it does return a changed dictionary then - that will still be used. The default implementation no longer returns - ``self.cleaned_data``. + that will still be used. Backwards incompatible changes in 1.7 ===================================== diff --git a/tests/forms_tests/tests/test_extra.py b/tests/forms_tests/tests/test_extra.py index ba835495c65..3bc22243fb7 100644 --- a/tests/forms_tests/tests/test_extra.py +++ b/tests/forms_tests/tests/test_extra.py @@ -620,6 +620,19 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin): self.assertTrue(f.is_valid()) self.assertEqual(f.cleaned_data['username'], 'sirrobin') + def test_changing_cleaned_data_nothing_returned(self): + class UserForm(Form): + username = CharField(max_length=10) + password = CharField(widget=PasswordInput) + + def clean(self): + self.cleaned_data['username'] = self.cleaned_data['username'].lower() + # don't return anything + + f = UserForm({'username': 'SirRobin', 'password': 'blue'}) + self.assertTrue(f.is_valid()) + self.assertEqual(f.cleaned_data['username'], 'sirrobin') + def test_changing_cleaned_data_in_clean(self): class UserForm(Form): username = CharField(max_length=10)