Opened 4 years ago

Closed 4 years ago

#20440 closed Bug (fixed)

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

Reported by: Tome Cvitan Owned by: Tome Cvitan
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

Description

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 4 years ago by Tome Cvitan

Owner: changed from nobody to Tome Cvitan
Status: newassigned

comment:2 Changed 4 years ago by Tome Cvitan

Has patch: set
Last edited 4 years ago by Tome Cvitan (previous) (diff)

comment:3 Changed 4 years ago by Tome Cvitan

Type: UncategorizedBug

comment:4 Changed 4 years ago by senko

Triage Stage: UnreviewedReady for checkin

Reviewed, looks good to me.

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

Resolution: fixed
Status: assignedclosed

In caf56ad1743778bad8af6b51b08f5baa342d4cd2:

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

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