[Django] #36618: Forms.add_error() misleading exception message

4 views
Skip to first unread message

Django

unread,
Sep 23, 2025, 2:22:19 PM9/23/25
to django-...@googlegroups.com
#36618: Forms.add_error() misleading exception message
------------------------+-----------------------------------------
Reporter: UEWBot | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+-----------------------------------------
This code creates a form and attempts to add an error for a single field
to it:

{{{
from django import forms
from django.core.exceptions import ValidationError

class FooForm(forms.Form):
the_field = forms.CharField(max_length=100)

exc = ValidationError({'the_field': 'Something is wrong with the field'})
form = FooForm()

form.add_error('the_field', exc)
}}}

It results in the following error message:
{{{
TypeError: The argument `field` must be `None` when the `error` argument
contains errors for multiple fields.
}}}

The reference to "errors for multiple fields" is just wrong - the error in
question is for a single field.

For background, in my case the ValidationError is raised by my custom
Model.clean(). What I really want to do it to map it from the Model field
to the form field (which in general may not have the same name). The error
message was quite confusing.
--
Ticket URL: <https://code.djangoproject.com/ticket/36618>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 23, 2025, 9:42:23 PM9/23/25
to django-...@googlegroups.com
#36618: Forms.add_error() misleading exception message
-------------------------------+----------------------------------------
Reporter: Chris Brand | Owner: The5cheduler
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by The5cheduler):

* owner: (none) => The5cheduler
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36618#comment:3>

Django

unread,
Sep 23, 2025, 9:43:57 PM9/23/25
to django-...@googlegroups.com
#36618: Forms.add_error() misleading exception message
-------------------------------------+-------------------------------------
Reporter: Chris Brand | Owner:
| The5cheduler
Type: Uncategorized | Status: assigned
Component: Testing framework | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by The5cheduler):

* component: Uncategorized => Testing framework
* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36618#comment:4>
Reply all
Reply to author
Forward
0 new messages