This commit is contained in:
Pk Patel 2025-11-17 16:31:09 +02:00 committed by GitHub
commit c63129bbe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -287,8 +287,8 @@ class BaseForm(RenderableFormMixin):
if hasattr(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

View file

@ -1710,6 +1710,19 @@ aria-describedby="id_birthday_error">
},
)
def test_add_error_validation_error_dict(self):
class FooForm(Form):
the_field = CharField(max_length=100)
exc = ValidationError({"the_field": "Something is wrong with the field."})
form = FooForm()
msg = (
"The argument `field` must be `None` when the `error` argument "
"is a ValidationError with an error_dict."
)
with self.assertRaisesMessage(TypeError, msg):
form.add_error("the_field", exc)
def test_has_error(self):
class UserRegistration(Form):
username = CharField(max_length=10)