Opened 3 years ago

Closed 3 years ago

#20440 closed Bug (fixed)

forms.CharField should return an exception if max_length is not an integer

Reported by: tome Owned by: tome
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In models.CharField you can define a verbose_name by placing a string as the first parameter, i.e. models.CharField("foo")

If you by mistake happen to define a forms.CharField with the same pattern, i.e. forms.CharField("foo"), there will be no error message and the input field will be rendered with the attribute maxlength="foo" which is invalid.

The proposed solution is to attempt to cast non-empty max_length and min_length values to an int in the init method of CharField.

Change History (5)

comment:1 Changed 3 years ago by tome

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to tome
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by tome

  • Has patch set
Last edited 3 years ago by tome (previous) (diff)

comment:3 Changed 3 years ago by tome

  • Type changed from Uncategorized to Bug

comment:4 Changed 3 years ago by senko

  • Triage Stage changed from Unreviewed to Ready for checkin

Reviewed, looks good to me.

comment:5 Changed 3 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In caf56ad1743778bad8af6b51b08f5baa342d4cd2:

Fixed #20440 -- Ensured CharField's max_length/min_length are integers

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