﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16986	Model.clean cannot report errors on individual fields	David Foster	nobody	"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."	New feature	closed	Forms	dev	Normal	fixed		David Foster danny.adair@… kmike84@… gp julie@… james@… Mark Young loic@…	Accepted	1	0	0	0	0	0
