Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#12510 closed (fixed)

ModelChoiceField.clean call to_python and validate from ChoiceField

Reported by: Petr Marhoun <petr.marhoun@…> 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

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.

Attachments (3)

django-model-choice-field-validation.diff (963 bytes ) - added by Petr Marhoun <petr.marhoun@…> 15 years ago.
django-model-choice-field-validation.2.diff (2.3 KB ) - added by Petr Marhoun <petr.marhoun@…> 15 years ago.
12510-against-12104.diff (2.7 KB ) - added by Honza Král 15 years ago.
Changed tests to UnitTest, simplified them a bit.

Download all attachments as: .zip

Change History (8)

by Petr Marhoun <petr.marhoun@…>, 15 years ago

comment:1 by Honza Král, 15 years ago

milestone: 1.2
Needs tests: set
Triage Stage: UnreviewedAccepted

Thanks, could you provide some tests for this behavior?

by Petr Marhoun <petr.marhoun@…>, 15 years ago

comment:2 by Petr Marhoun <petr.marhoun@…>, 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 Honza Král, 15 years ago

Attachment: 12510-against-12104.diff added

Changed tests to UnitTest, simplified them a bit.

comment:3 by Honza Král, 15 years ago

Needs tests: unset

Added a simpler test case in unittest format...

comment:4 by jkocherhans, 15 years ago

Resolution: fixed
Status: newclosed

(In [12211]) Fixed #12510. Changed ModelChoiceField to stop using some of its superclasses implementation. This could cause more than one query when generating choices. Thanks, Petr Marhoun and Honza Kral.

comment:5 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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