Skip to content

Commit e49e14f

Browse files
nileshpaharijacobtylerwalls
authored andcommitted
Fixed #36618 -- Corrected error message in BaseForm.add_error().
The error message now correctly states that the error argument is a dictionary.
1 parent 5a851bd commit e49e14f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

django/forms/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def add_error(self, field, error):
288288
if field is not None:
289289
raise TypeError(
290290
"The argument `field` must be `None` when the `error` "
291-
"argument contains errors for multiple fields."
291+
"argument is a dictionary."
292292
)
293293
else:
294294
error = error.error_dict

tests/forms_tests/tests/test_forms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,13 @@ def clean(self):
16601660
with self.assertRaisesMessage(ValueError, "has no field named"):
16611661
f.add_error("missing_field", "Some error.")
16621662

1663+
with self.assertRaisesMessage(
1664+
TypeError,
1665+
"The argument `field` must be `None` when the `error` argument is a "
1666+
"dictionary.",
1667+
):
1668+
f.add_error("password1", ValidationError({"password1": "Some error."}))
1669+
16631670
def test_update_error_dict(self):
16641671
class CodeForm(Form):
16651672
code = CharField(max_length=10)

0 commit comments

Comments
 (0)