#23354: ModelChoiceField does not handle MultipleObjectsReturned
----------------------------+--------------------
Reporter: kezabelle | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
As far as I can gather [that is, this hasn't actually bitten me], the
[https://github.com/django/django/blob/deed00c0d803d324a3dfdeba52458b6b009c1a90/django/forms/models.py#L1182
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23354>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.67656430860277b86014ae77ccdb9906%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.