Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#13631 closed (fixed)

IntegerField has no attributes max_value and min_value (1.2 regression)

Reported by: Miloslav Pojman Owned by: nobody
Component: Forms Version: 1.2
Severity: Keywords: regression
Cc: Greg Wogan-Browne Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Attributes min_value and max_value are no longer set on IntegerField, FloatField and DecimalField in Django 1.2.

Note these attributes are documented: http://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.IntegerField.max_value.

I'm using them to generate some javascript validation.

Attachments (1)

tests.py (2.4 KB) - added by Miloslav Pojman 6 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by Erik Romijn

Needs documentation: set
Triage Stage: UnreviewedAccepted

I haven't seen the old code, but it seems IntegerField now does min/max using django.core.validators. The fields are indeed not set in the code.
I think the documentation is not very clear on whether or not these fields should exist.

So, either the fields should be added, or the documentation should be clarified so that it doesn't suggests these fields being there.
I don't see an easy alternative to get them from the field instance.

comment:2 Changed 7 years ago by Erik Romijn

Triage Stage: AcceptedDesign decision needed

This would probably actually fit better in DDN.

comment:3 Changed 6 years ago by Miloslav Pojman

This can be easily fixed by setting a field attribute in addition to adding a validator - similar to current CharField implementation.

The problem with this approach is that attribute value and validator can become easily inconsistent. Therefore from my point of view the design decision needed here is whether form field attributes are mutable or not. For example: Can be CharField min_length set in form init method?

I am attaching more tests.

Changed 6 years ago by Miloslav Pojman

Attachment: tests.py added

comment:4 Changed 6 years ago by Greg Wogan-Browne

Cc: Greg Wogan-Browne added
Keywords: regression added

comment:5 Changed 6 years ago by Russell Keith-Magee

Triage Stage: Design decision neededAccepted

The documentation says "Takes two optional arguments for validation". It makes no guarantees about the field having an attribute. However, it's trivial to fix, and other attributes (e.g., max_digits on DecimalField, max_length on CharField), so it's worth doing.

comment:6 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [15194]) Fixed #13631 -- Made sure that max_length and min_length are retained as attributes on form fields. Thanks to mila for the report.

comment:7 Changed 6 years ago by Russell Keith-Magee

(In [15195]) [1.2.X] Fixed #13631 -- Made sure that max_length and min_length are retained as attributes on form fields. Thanks to mila for the report.

Backport of r15194 from trunk.

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