newforms.util.ValidationError has nothing in common with core.validators.ValidationError. Why?

3 views
Skip to first unread message

Max Derkachev

unread,
Mar 20, 2007, 11:03:14 AM3/20/07
to Django developers
The ValidationError exception from newforms knows nothing of
ValidationError from validators.
That make useless any validators, builtin or custom, that was defined
for model fields, if one wanted to use them in related form field
validation. If the first at least extended the second, we could do
something like this for model fields in forms:

field = forms.Field(......)
field.clean = lambda value: [x(value) for x in
myModelField.validator_list] and value

Current logic in BaseForm.full_clean checks for
newforms.util.ValidationError only, rendering any model fields'
validators useless.

I suppose, newforms.util.ValidationError extend
core.validators.ValidationError, or full_clean should wait also for
core.validators.ValidationError.

I haven't filled a ticket yet, because I thought the matter should be
discussed here first.

Regards,
Max

Adrian Holovaty

unread,
Mar 20, 2007, 11:22:13 AM3/20/07
to django-d...@googlegroups.com
On 3/20/07, Max Derkachev <max.de...@gmail.com> wrote:
> The ValidationError exception from newforms knows nothing of
> ValidationError from validators.
> That make useless any validators, builtin or custom, that was defined
> for model fields, if one wanted to use them in related form field
> validation. If the first at least extended the second, we could do
> something like this for model fields in forms:
>
> field = forms.Field(......)
> field.clean = lambda value: [x(value) for x in
> myModelField.validator_list] and value
>
> Current logic in BaseForm.full_clean checks for
> newforms.util.ValidationError only, rendering any model fields'
> validators useless.
>
> I suppose, newforms.util.ValidationError extend
> core.validators.ValidationError, or full_clean should wait also for
> core.validators.ValidationError.

Hi Max,

django.core.validators is going away in the long term. Use
django.newforms if you want your code to be forwards-compatible.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

Max Derkachev

unread,
Mar 20, 2007, 11:34:54 AM3/20/07
to Django developers
Hi, Adrian,

> Use django.newforms if you want your code to be forwards-compatible.

Sure. But why not to use the [one] validators set (or at least, one
exception class) in the long term, both in models and forms?
What to do with the validators that are used in models, including
builtin? Model.validate is still uses core.validators, BTW. Is
validation in models also going away in the long term?

Regards,
Max

Adrian Holovaty

unread,
Mar 20, 2007, 3:20:04 PM3/20/07
to django-d...@googlegroups.com
On 3/20/07, Max Derkachev <max.de...@gmail.com> wrote:
> Sure. But why not to use the [one] validators set (or at least, one
> exception class) in the long term, both in models and forms?
> What to do with the validators that are used in models, including
> builtin? Model.validate is still uses core.validators, BTW. Is
> validation in models also going away in the long term?

Hey Max,

Things are in flux with newforms right now, as they've been for a
while, so the only thing I can say is, please be patient. We're aware
of the fact that things are in flux, and, speaking as a perfectionist,
chances are that it bothers me even more than it bothers you. :)

Max Derkachev

unread,
Mar 22, 2007, 10:00:02 AM3/22/07
to Django developers
Hi Adrian,

> Things are in flux with newforms right now, as they've been for a
> while, so the only thing I can say is, please be patient. We're aware
> of the fact that things are in flux, and, speaking as a perfectionist,
> chances are that it bothers me even more than it bothers you. :)

Thanks for clarification!
Hacking a lot with newforms these days. Great stuff. MultiValueField/
MultiWidget are awesome.
Will do my best to help. Found some bugs, the patches will be soon at
trac.

Max

Reply all
Reply to author
Forward
0 new messages