Opened 7 years ago

Closed 5 years ago

#8104 closed (duplicate)

IntegerField max_value & min_value errors require a %s

Reported by: Chris Jones <chris@…> Owned by: nobody
Component: Forms Version:
Severity: Keywords: IntegerField max_value min_value TypeError
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When trying to set the max_value or min_value error message on an IntegerField without %s in the custom string a TypeError is raised.

Example: phone = forms.IntegerField(max_value=10 error_messages={'max_value': 'Please enter a phone number with 10 digits.')

Exception Type: TypeError
Exception Value: not all arguments converted during string formatting
Exception Location: /usr/local/lib/python2.5/site-packages/django/forms/fields.py in clean, line 185

To stop the TypeError from being raised I have to add %s somewhere in my custom error message string.
Example: phone = forms.IntegerField(max_value=10 error_messages={'max_value': 'Please enter a phone number with %s digits.')

Either the documentation needs to be updated to explain this or the error message should be able to handle a string with or without the max_value/min_value being called.

Change History (5)

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Forms IntegerField max_value & min_value error message TypeError to IntegerField max_value & min_value errors require a %s
  • Triage Stage changed from Unreviewed to Design decision needed

I agree, this isn't the best. The design decision is to be whether we should fix it or just update the docs.

Personally, I'd like to see them as parenthesized mapping keys ('Please enter a value less than %(max_value)s')

comment:2 Changed 6 years ago by emonk

  • Version SVN deleted

I agree, make a custom min_value or max_value error_messages with %s or whitout %s must be enable for forms.IntegerField

comment:3 Changed 6 years ago by hakanw

Please, this really needs to be added to the documentation.

comment:4 Changed 5 years ago by adamv

As of 1.3-alpha-1 (and possibly earlier), all form field error messages that have data available use mapping keys. I've opened a new ticket w/ a patch to document these keys: http://code.djangoproject.com/ticket/14708

Recommend resolving this issue as a duplicate of that new issue.

comment:5 Changed 5 years ago by gabrielhurley

  • Resolution set to duplicate
  • Status changed from new to closed

As adamv points out, the design decision seems to have been made (by standardizing the use of mapping keys for 1.3), so that would make this a docs ticket. And since adamv was kind enough to create #14708 with a complete patch (looks complete at least from a cursory review), I'm closing this as a duplicate.

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