diff --git a/django/forms/forms.py b/django/forms/forms.py index 513a7edba2..6dbc2c6639 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -285,14 +285,10 @@ class BaseForm(RenderableFormMixin): error = ValidationError(error) if hasattr(error, "error_dict"): - if field is None: - error = error.error_dict - # Raise an error if the ValidationError contains more than one - # item or if the only item's key doesn't match the form field. - elif len(error.error_dict) != 1 or field not in error.error_dict: + if field is not None: raise TypeError( - "The argument `field` must be `None` when the `error` " - "argument contains errors for multiple fields." + "The argument `field` must be `None` when the `error` argument " + "is a ValidationError with an error_dict." ) else: error = error.error_dict @@ -316,7 +312,7 @@ class BaseForm(RenderableFormMixin): field_id=self[field].auto_id, ) self._errors[field].extend(error_list) - if hasattr(self, "cleaned_data") and field in self.cleaned_data: + if field in self.cleaned_data: del self.cleaned_data[field] def has_error(self, field, code=None):