#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019977cfd161-9a2dc3b2-444b-4cf3-94a6-5d4f0e0135e0-000000%40eu-central-1.amazonses.com.

Reply via email to