Opened 19 years ago

Closed 18 years ago

#2182 closed defect (invalid)

IntegerField gets bogus validator_list from parent class

Reported by: James Bennett Owned by: Jacob
Component: Documentation Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.forms.IntegerField is a subclass of django.forms.TextField; this is all well and good, and makes sense, except for the last line of IntegerField's __init__, which calls TextField's __init__; this adds 'hasNoNewlines' and 'isValidLength' to the IntegerField's validator_list. This will end up causing exceptions during validation because integers aren't iterable and don't have a length.

The solution to this looks like it will involve changing IntegerField's __init__ to supply all the needed attributes without calling TextField's __init__, or possibly just sticking with what we have and culling the bad validators from validator_list after the fact,

Change History (3)

comment:1 by James Bennett, 19 years ago

Component: ValidatorsDocumentation
Owner: changed from Adrian Holovaty to Jacob
priority: highnormal
Severity: blockernormal

Actually, I just realized the problem here: since we expect manipulators to be dealing with input from HTML forms, which will always be strings, this is actually correct. It just means that to programmatically use manipulators you have to call str on these fields to make sure the manipulator gets what it expects. My bad.

However, that makes this a documentation bug, because the manipulator docs don't mention this.

comment:2 by James Bennett, 19 years ago

And while I'm mentioning documentation bugs, it'd be nice for the manipulator docs to mention that if you only show a subset of the model's fields on an HTML page, you'll need to populate any other required fields in new_data manually in your view before you try to validate or save.

comment:3 by Gary Wilson <gary.wilson@…>, 18 years ago

Resolution: invalid
Status: newclosed

There is a note in the Validotors section of the Forms, fields, and manipulators documentation that states "At the point validators are called all data will still be strings (as do_html2python hasn't been called yet)."

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