Opened 5 years ago

Closed 5 years ago

#30163 closed Bug (invalid)

UserCreationForm's error_messages for 'password1' and 'password2' can't be overidden by form's Meta.error_essages

Reported by: Oskar Haller Owned by: nobody
Component: contrib.auth Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Oskar Haller)

class UserRegisterForm(UserCreationForm):
    """
    Form class to register a new user
    """
    class Meta:
        #https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#modelforms-overriding-default-fields
        model = User
        fields = (...'password1',  'password2')
        error_messages = {
            'password1': {
                'required': _('Please enter a password.')
            },
            'password2': {
                'required': _('Please enter a password.')
            }
        }

Instead of 'Please enter a password' I get 'This field is required.'

For all other fields the overrriding works fine

Change History (3)

comment:1 by Oskar Haller, 5 years ago

Type: UncategorizedBug

comment:2 by Oskar Haller, 5 years ago

Description: modified (diff)
Summary: error_messages password1 'required' can not be overwrittenerror_messages 'password1' 'required' can not be overidden

comment:3 by Tim Graham, 5 years ago

Component: Uncategorizedcontrib.auth
Resolution: invalid
Status: newclosed
Summary: error_messages 'password1' 'required' can not be overiddenUserCreationForm's error_messages for 'password1' and 'password2' can't be overidden by form's Meta.error_essages

error_messages is a dictionary of model field names mapped to a dictionary of error messages. It doesn't work for non-model fields like password1 and password2.

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