One possible way forward is to add "errors" argument to the clean()
method. Then it would be possible to use the same API everywhere by
doing errors.add_error('my_field', 'My Error message').

I don't know how strongly we feel about breakages caused by new
arguments to methods. We broke model.save() this way some time ago IIRC.

 - Anssi

On Thu, 2014-11-20 at 14:02 +0700, Loic Bistuer wrote:
> Neither will go away, `ValidationError(dict)` is used internally to carry 
> errors from the model layer to the form layer, and `add_error()` is used 
> internally to interpret the `ValidationError` raised throughout the system; 
> basically any `raise ValidationError` is followed by a call to `add_error()`.
> 
> One benefit of `add_error()` is that it's available from outside the form 
> validation methods, it's much less fiddly to add an error from a view if you 
> are using `add_error()`. It also doubles as a low-level API that can be used 
> to implement custom validation logic, for instance `ModelForm` uses it to 
> plug in model validation.
> 
> Fore more background on `add_error()` as a public API: 
> https://code.djangoproject.com/ticket/20867#comment:4
> 
> -- 
> Loic
> 
> > On Nov 20, 2014, at 1:19 AM, Carl Meyer <c...@oddbird.net> wrote:
> > 
> > Yes, the add_error() API is slightly less verbose if you have multiple
> > different errors you may want to flag. I don't think that difference is
> > worth having to remember two different ways to do it, but I don't really
> > feel strongly enough about it to push for what would essentially amount
> > to deprecating `Form.add_error()`.
> > 
> > I am satisfied as long as `raise ValidationError(dict)` continues to
> > work in both places, so I can use it in my code :-)
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1416468019.8931.243.camel%40TTY32.
For more options, visit https://groups.google.com/d/optout.

Reply via email to