Opened 14 years ago

Closed 13 years ago

Last modified 13 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: no UI/UX: no

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 14 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Sasha Romijn, 14 years ago

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 by Sasha Romijn, 14 years ago

Triage Stage: AcceptedDesign decision needed

This would probably actually fit better in DDN.

comment:3 by Miloslav Pojman, 14 years ago

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.

by Miloslav Pojman, 14 years ago

Attachment: tests.py added

comment:4 by Greg Wogan-Browne, 13 years ago

Cc: Greg Wogan-Browne added
Keywords: regression added

comment:5 by Russell Keith-Magee, 13 years ago

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 by Russell Keith-Magee, 13 years ago

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 by Russell Keith-Magee, 13 years ago

(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