#18431 closed Bug (invalid)
TypedChoiceField doesn't use self.coerce in its clean() and prepare_value() methods
Reported by: | Łukasz Langa | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
One of the points of the clean()
method is to clean the data to the correct type. When a coerce
function is defined for a TypedChoiceField
, it should then be used by clean()
and prepare_value()
as well.
Change History (3)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
You're right. coerce
is indeed invoked in TypedChoiceField.to_python()
. The problem however is with the fact that this method first calls ChoiceField.to_python()
which blatantly runs smart_unicode(value)
regardless of whether that's compatible with coerce
or not. Moreover, the following line in TypedChoiceField.to_python()
reads:
super(TypedChoiceField, self).validate(value)
which means it skips TypedChoiceField.validate()
and runs the super ChoiceField.validate()
instead. Is that conscious design or is it a bug?
Also, note that prepare_value()
does not use coerce
at all.
comment:3 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
You're describing a very high level issue with the design of Django's form. This doesn't lead to any clear, actionnable items. As a consequence the ticket has languished here for five months without feedback.
I suggest taking this topic to the django-developers mailing list. You'll reach a wider audience and it'll be a better medium for the discussion. You should give more details; try to frame the problem and explain your proposal.
If the discussion determines that Django's behavior should be changed — taking into account backward-compatibility requirements — then you're welcome to add details to this ticket and reopen it, or to open a new one.
Clean is returning coerced value. Because clean is calling to_python method.