#15069: ValidationError message isn't helpful in tracking down the field that
fails
validation
-------------------------------------+-------------------------------------
Reporter: Steve Steiner | Owner:
<ssteinerX@…> | anubhav9042
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: ValidationError, | Triage Stage: Accepted
exception, error message | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by anubhav9042):
* cc: anubhav9042@… (added)
* version: 1.2 => master
Comment:
I have looked into this and there are some changes from when the ticket
was filed.
In `DateTimeField` in `db/models/fields/__init__.py`
{{{
default_error_messages = {
'invalid': _("'%(value)s' value has an invalid format. It must be
in "
"YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."),
'invalid_date': _("'%(value)s' value has the correct format "
"(YYYY-MM-DD) but it is an invalid date."),
'invalid_datetime': _("'%(value)s' value has the correct format "
"(YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) "
"but it is an invalid date/time."),
}
}}}
But in `DateTimeField` in `django/forms/fields.py`
{{{
default_error_messages = {
'invalid': _('Enter a valid date/time.'),
}
}}}
There have been a lot of changes in the source code from the time it was
filed. So it seems that this is changed in `db/models/fields/__init__.py`
which is the place where Steve mentions he found the problem.
But the component in the the ticket says `Forms`, in which the problem
still exists as the errors from the forms still are not at all good if
they just say `Enter a valid date/time.` I am not sure that how the forms
got there errors earlier, probably from models itself, but atleast now it
is not.
- In many of the form fields, the error messages are much better and self-
explanatory but the above and in many places like `DateField`,
`TimeField`, `DateTimeField`, `URLField` and maybe some more, I think we
can make those better just like in the `db/models/fields/__init__.py`.
- I think we should make `default_error_messages` in forms and models
similar. In `models`, every error message contains the faulty `value` but
in `forms`, it does not.
So what I think that atleast we should improve errors in the form fields
that I listed out above and other similar ones and also we can decide on
the second point, i.e. whether we should pass the value onto the errors in
the all form errors as is done in few so as to make it similar to that in
models.
--
Ticket URL: <https://code.djangoproject.com/ticket/15069#comment:8>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/093.68375173f026110c469088cbacfe793e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.