Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13631 closed (fixed)

IntegerField has no attributes max_value and min_value (1.2 regression)

Reported by: mila Owned by: nobody
Component: Forms Version: 1.2
Severity: Keywords: regression
Cc: wogan 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 mila 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by erikr

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by erikr

  • Triage Stage changed from Accepted to Design decision needed

This would probably actually fit better in DDN.

comment:3 Changed 5 years ago by mila

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 5 years ago by mila

comment:4 Changed 5 years ago by wogan

  • Cc wogan added
  • Keywords regression added

comment:5 Changed 5 years ago by russellm

  • Triage Stage changed from Design decision needed to Accepted

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 5 years ago by russellm

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

(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 5 years ago by russellm

(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