From e49e14fd9032feb7a8cf254658ac4e74a4ffb712 Mon Sep 17 00:00:00 2001 From: Nilesh Kumar Pahari Date: Fri, 19 Dec 2025 02:15:56 +0530 Subject: Fixed #36618 -- Corrected error message in BaseForm.add_error(). The error message now correctly states that the error argument is a dictionary. --- django/forms/forms.py | 2 +- tests/forms_tests/tests/test_forms.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index 760ba7b767..ce64f6286e 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -288,7 +288,7 @@ class BaseForm(RenderableFormMixin): if field is not None: raise TypeError( "The argument `field` must be `None` when the `error` " - "argument contains errors for multiple fields." + "argument is a dictionary." ) else: error = error.error_dict diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 8cc1fecf0a..7f698ad706 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1660,6 +1660,13 @@ aria-describedby="id_birthday_error"> with self.assertRaisesMessage(ValueError, "has no field named"): f.add_error("missing_field", "Some error.") + with self.assertRaisesMessage( + TypeError, + "The argument `field` must be `None` when the `error` argument is a " + "dictionary.", + ): + f.add_error("password1", ValidationError({"password1": "Some error."})) + def test_update_error_dict(self): class CodeForm(Form): code = CharField(max_length=10) -- cgit v1.3