Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#21339 closed Cleanup/optimization (fixed)

Form error message "required" instead of "invalid"

Reported by: Eduardo Klein Owned by: nobody
Component: Forms Version: 1.6-beta-1
Severity: Release blocker Keywords: form error_message
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Install the django-custom-user (pip install django-custom-user). The source code is at https://github.com/recreatic/django-custom-user

Add 'custom_user' to INSTALLED_APPS and set AUTH_USER_MODEL = 'custom_user.EmailUser'

Run ./manage.py test custom_user

The test custom_user.tests.EmailUserCreationFormTest.test_invalid_data fails. Here is the code:

data = {
        'email': 'testclient',
        'password1': 'test123',
        'password2': 'test123',
       }
form = EmailUserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["email"].errors,
                 [force_text(form.fields['email'].error_messages['invalid'])])

In Django 1.6c1,

form.fields['email'].error_messages

has 'required' as a key and its corresponding message instead of 'invalid' and its corresponding message.

In Django 1.5.5, it works fine.

Change History (6)

comment:1 by Claude Paroz, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Ticket at the origin of the change is #17051, commit is [2f121dfe635b3f].

The rationale is that the error message is not primarily set by the form field, but by the validator(s) attached to the field.
In Django 1.6, the test above should be:

from django.core.validators import EmailValidator
self.assertEqual(form["email"].errors, [force_text(EmailValidator.message)])

Accepted on the base that a note might be added in the Backwards incompatible changes in 1.6 section of the release notes.

comment:2 by Claude Paroz, 10 years ago

Has patch: set

Proposal:

diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index 651938e..afa44d2 100644
--- a/docs/releases/1.6.txt
+++ b/docs/releases/1.6.txt
@@ -830,6 +830,10 @@ Miscellaneous
   changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
   :class:`~django.forms.ModelMultipleChoiceField`.
 
+* Several form field's :attr:`~django.forms.Field.error_messages` have been
+  suppressed because they were duplicates of error messages coming from the
+  appropriate field validator(s).
+
 * There have been changes in the way timeouts are handled in cache backends.
   Explicitly passing in ``timeout=None`` no longer results in using the
   default timeout. It will now set a non-expiring timeout. Passing 0 into the

comment:3 by Tim Graham, 10 years ago

Patch needs improvement: set

I think we should also include an example like the one offered in the description. Reading the note without reading the rest of the this ticket left me wondering what it meant.

comment:4 by Aymeric Augustin, 10 years ago

I don't think we've documented the field error messages and guarantee backwards compatibility for them.

Of course more documentation is generally better, we can add this to the release notes.

Claude, I suggest listing all fields, to make the message as useful as possible. Proposal:

* Some :attr:`~django.forms.Field.error_messages` for
  :class:`~django.forms.fields.IntegerField`,
  :class:`~django.forms.fields.EmailField`,
  :class:`~django.forms.fields.IPAddressField`,
  :class:`~django.forms.fields.GenericIPAddressField`, and
  :class:`~django.forms.fields.SlugField` have been suppressed because they
  duplicated error messages already provided by validators tied to the fields.
Last edited 10 years ago by Aymeric Augustin (previous) (diff)

comment:5 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 0d9c1499901480ed52c08e1b94ecc80c7b55bc0e:

Fixed #21339 -- Documented removal of some form field error messages

comment:6 by Claude Paroz <claude@…>, 10 years ago

In 8f104bb8d51835c240bbc7f468032b798a263b24:

[1.6.x] Fixed #21339 -- Documented removal of some form field error messages

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