diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 4928065e9d..f47700f857 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -44,7 +44,6 @@ class BaseForm(StrAndUnicode): self.data = data or {} self.auto_id = auto_id self.prefix = prefix - self.clean_data = None # Stores the data after clean() has been called. self.__errors = None # Stores the errors after clean() has been called. def __unicode__(self): @@ -137,11 +136,11 @@ class BaseForm(StrAndUnicode): """ Cleans all of self.data and populates self.__errors and self.clean_data. """ - self.clean_data = {} errors = ErrorDict() if self.ignore_errors: # Stop further processing. self.__errors = errors return + self.clean_data = {} for name, field in self.fields.items(): # value_from_datadict() gets the data from the dictionary. # Each widget type knows how to retrieve its own data, because some @@ -160,7 +159,7 @@ class BaseForm(StrAndUnicode): except ValidationError, e: errors[NON_FIELD_ERRORS] = e.messages if errors: - self.clean_data = None + delattr(self, 'clean_data') self.__errors = errors def clean(self): diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 0852fbcf0e..6e2f898645 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1544,6 +1544,10 @@ Empty dictionaries are valid, too. {'first_name': [u'This field is required.'], 'last_name': [u'This field is required.'], 'birthday': [u'This field is required.']} >>> p.is_valid() False +>>> p.clean_data +Traceback (most recent call last): +... +AttributeError: 'birthday' object has no attribute 'clean_data' >>> print p @@ -1572,6 +1576,10 @@ Form.is_valid() will return False. {} >>> p.is_valid() False +>>> p.clean_data +Traceback (most recent call last): +... +AttributeError: 'birthday' object has no attribute 'clean_data' >>> print p @@ -1611,8 +1619,9 @@ u'