Opened 13 years ago

Closed 13 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

Description

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/fields.py", line 155, in clean
    self.run_validators(value)
  File "/home/insin/Virtualenvs/django-trunk/src/django/django/forms/fields.py", line 144, in run_validators
    raise ValidationError(errors)
django.core.exceptions.ValidationError: [u'Enter a valid value.']
>>> import django
>>> django.get_version()
'1.4a1'

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:

https://github.com/insin/django/compare/validators-error-messages

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, 13 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #17051

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