Opened 12 years ago

Closed 12 years ago

#17679 closed Bug (duplicate)

Error messages from field.validators never used if the ValidationError has a code matching an error message on the Field

Reported by: Jonathan Buchanan Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Given the following field, I would have expected that validate_email's error message would haven been displayed:

>>> from django.conf import settings
>>> settings.configure()
>>> from django import forms
>>> from django.core import validators
>>> f = forms.CharField(validators=[validators.validate_email])
>>> f.clean('@@@@@@')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/insin/Virtualenvs/django-trunk/src/django/django/forms/", line 155, in clean
  File "/home/insin/Virtualenvs/django-trunk/src/django/django/forms/", line 144, in run_validators
    raise ValidationError(errors)
django.core.exceptions.ValidationError: [u'Enter a valid value.']
>>> import django
>>> django.get_version()

The root issue is that many of the django.core.validators use the "invalid" error code, which is always going to be defined on the field as it's a default. I have a branch on GitHub which has one approach to updating this behaviour - using the validators' own error messages unless the message code has been customised on the field instance. The tests demonstrate a use case extending RegexValidator, which was raised as an issue in my JavaScript port of django.forms:

Another approach would be to change the codes used by the OOTB validators away from 'invalid', as is already the case with BaseValidator and classes which extend it.

Change History (1)

comment:1 by Claude Paroz, 12 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #17051

Note: See TracTickets for help on using tickets.
Back to Top