Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23150 closed Bug (invalid)

RegexField invalid message_error returns error list.

Reported by: e2jeyy@… Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords: RegexField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I encountered an issue when using the RegexField as seen below:

>>> from django import forms
>>> username = forms.RegexField(regex=r'^[\w]+$', error_message={'invalid': 'Does not meet requirement'})
>>> username.clean('')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/EJey/Documents/virtualenvs/mysocialenv/lib/python2.7/site-packages/django/forms/", line 150, in clean
  File "/Users/EJey/Documents/virtualenvs/mysocialenv/lib/python2.7/site-packages/django/forms/", line 139, in run_validators
    raise ValidationError(errors)
ValidationError: [u"{'invalid': 'Does not meet requirement'}"]

What should be returned is: ValidationError: [u'Does not meet requirement'] without the curly braces and the information about the type of error.
From the djanago source there is a comment under the RegexField that states # error_message is just kept for backwards compatibility This is clearly not the case.

Change History (2)

comment:1 by Baptiste Mispelon, 10 years ago

Resolution: invalid
Status: newclosed


The error_message argument should be a simple string, not a dictionary, like so: username = forms.RegexField(regex=r'^[\w]+$', error_message='Does not meet requirement').

However, you should use the more modern version with error_messages (note the final s): username = forms.RegexField(regex=r'^[\w]+$', error_messages={'invalid': 'Does not meet requirement'}).


comment:2 by Baptiste Mispelon, 10 years ago

For what it's worth, I opened a ticket to remove this error_message argument altogether: #23151.

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