ModelChoiceField does not handle MultipleObjectsReturned
|Reported by:||kezabelle||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As far as I can gather [that is, this hasn't actually bitten me], the to_python for ModelChoiceField does not catch the queryset model's MultipleObjectsReturned exception, which in most cases will be fine because the query will be against the pk, which is ostensibly unique unless a user has gone out of their way to break things.
However, given the ability to use to_field_name (which was recently documented [in #21860], increasing the likelihood of it's usage) it is feasible that a user would end up using a field which is not unique (or even spans a relationship?), and thus in a simple key:value lookup could return multiple rows.
This would also technically affect the ModelMultipleChoiceField, whose superclass is ModelChoiceField and whose to_python method is used for each value.