#16986: Model.clean cannot report errors on individual fields
----------------------------+--------------------
Reporter: davidfstr | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: SVN
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Any {{{ValidationError}}} raised by {{{Model.clean()}}} is always
attributed to "{{{__all__}}}" ({{{NON_FIELD_ERRORS}}}), even if the
{{{ValidationError}}} was created with a dictionary that associated errors
with particular fields.
For example, in the following code...
{{{
class Spot(models.Model):
def clean(self):
errors = defaultdict(list)
if not self.name and not self.address_line_1:
message = 'Spots must have either a name, address, or both
specified.'
errors['name'].append(message)
errors['address_line_1'].append(message)
if len(errors):
raise ValidationError(errors)
}}}
...even though the error dictionary was specified explicitly, the
dictionary seen by Django is:
{{{
errors['__all__'].append(message) # expected: name
errors['__all__'].append(message) # expected: address_line_1
}}}
I have traced the issue to BaseModelForm._post_clean: it ignores the error
dictionary completely, using the error list instead (which lacks the field
name associations).
I have attached a patch. It passes all unit tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/16986>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.