From 408d4310291cd1287f3dbc05aaeb5d205eba8751 Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Thu, 21 Jan 2010 02:28:03 +0000 Subject: Fixed #12596. Calling super from a ModelForm's clean method is once again optional. Failing to call super only skips unique validation as documented. Thanks for the initial patch and tests, carljm. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12269 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/forms.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'django/forms/forms.py') diff --git a/django/forms/forms.py b/django/forms/forms.py index c53a901e73..6f7a8ce97d 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -263,6 +263,12 @@ class BaseForm(StrAndUnicode): # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return + self._clean_fields() + self._clean_form() + if self._errors: + delattr(self, 'cleaned_data') + + def _clean_fields(self): for name, field in self.fields.items(): # value_from_datadict() gets the data from the data dictionaries. # Each widget type knows how to retrieve its own data, because some @@ -282,12 +288,12 @@ class BaseForm(StrAndUnicode): self._errors[name] = self.error_class(e.messages) if name in self.cleaned_data: del self.cleaned_data[name] + + def _clean_form(self): try: self.cleaned_data = self.clean() except ValidationError, e: self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages) - if self._errors: - delattr(self, 'cleaned_data') def clean(self): """ -- cgit v1.3