#12510 closed (fixed)
ModelChoiceField.clean call to_python and validate from ChoiceField
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
Comment in ModelChoiceField says: This class is a subclass of ChoiceField for purity, but it doesn't actually use any of ChoiceField's implementation.
But with model level validation method ModelChoiceField.clean calls Field.clean and it calls self.to_python and self.validate, in reality ChoiceField.to_python and ChoiceField.validate. And for ModelChoiceField these methods are useless and can be harmful - for example (my problem) with hidden ModelChoiceField choices were not created but they are now, it could be very ineffective.
Change History (8)
by , 15 years ago
Attachment: | django-model-choice-field-validation.diff added |
---|
comment:1 by , 15 years ago
milestone: | → 1.2 |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
by , 15 years ago
Attachment: | django-model-choice-field-validation.2.diff added |
---|
comment:2 by , 15 years ago
I attached test - it is quite artificial ("problem" in test could be solved with simple "select_related" in queryset), but it should prove that choices are really generated.
by , 15 years ago
Attachment: | 12510-against-12104.diff added |
---|
Changed tests to UnitTest, simplified them a bit.
comment:4 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks, could you provide some tests for this behavior?