#16986: Model.clean cannot report errors on individual fields
-----------------------------+------------------------------------
Reporter: davidfstr | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: SVN
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by carljm):
* needs_docs: => 1
* needs_better_patch: => 1
* type: Bug => New feature
* needs_tests: => 1
* stage: Unreviewed => Accepted
Comment:
Thanks for the report and patch!
I'd call this a new feature rather than a bug, since it's never been
documented anywhere that you can raise a dict-style `ValidationError` from
`clean` to get errors associated with particular fields. That said, it's a
useful feature and one that I've wanted before, and the implementation is
trivial and non-invasive.
Rather than spreading the `hasattr(..., "message_dict") disease outside
`ValidationError`, I think the patch should introduce a new `has_dict`
property on `ValidationError` that keeps that check internal to the
implementation (and may as well clean up the internal `hasattr` uses to
use the new property too).
Also, a note should be added to the docs that this is possible, and
showing how its done. And we need a new test demonstrating that it works.
--
Ticket URL: <https://code.djangoproject.com/ticket/16986#comment:1>
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.