#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 , 11 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 11 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 , 11 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 , 11 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.
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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:
Accepted on the base that a note might be added in the Backwards incompatible changes in 1.6 section of the release notes.