#17840 closed Bug (fixed)
Overriding form field error messages without argument causes string formatting error.
Reported by: | klein4 | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Something like this in a form's init method
self.fields['my_choice_field'].error_messages['invalid_choice'] = u'Constant string'
will throw an error because of the following line in django/forms/models.py (line 1015):
raise ValidationError(self.error_messages['invalid_choice'] % val)
This method of string formatting forces the user's custom error message to contain a '%s' argument, like the default error message does. A dictionary-based string formatting operation like
self.error_messages['invalid_choice'] % {'foo': bar}
would fix this problem.
Attachments (2)
Change History (8)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 12 years ago
Attachment: | 17840-1.diff added |
---|
comment:2 by , 12 years ago
Has patch: | set |
---|
I understand that this patch might be slightly backwards incompatible, but I think this needs to be fixed.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Now that the 1.4 branch is string-frozen, this will have to wait for 1.5.