However, it only cathes ValueError, assuming that filter() is capable of
even using the value.
If the value is a weird data type like list or dict, the call to filter
throws TypeError.
ModelMultipleChoiceField.clean should catch TypeError, in addition to
ValueError, on line 1187.
Here is gist with a complete minimal app that demonstrates how this can
happen: https://gist.github.com/thnee/8e7c6b22f350582efe57/
Specifically the file: 4. views.py.
It is tested with 1.6.5, using 100% default settings in a clean test
project.
--
Ticket URL: <https://code.djangoproject.com/ticket/22808>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: maxime.turcotte@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:1>
* version: 1.5 => 1.6
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:2>
* keywords: modelform => modelform, afraid-to-commit
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:3>
* stage: Unreviewed => Accepted
Comment:
Hi,
Looking at `django/forms/fields.py`, it seems that there is precedent for
catching `(ValueError, TypeError)` so I think it makes sense.
The same error seems to be present in `ModelChoiceField` so both should be
fixed as part of this ticket.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:4>
Comment (by anonymous):
Created pull request: https://github.com/django/django/pull/2813
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:5>
* needs_tests: 0 => 1
Comment:
It needs a test (or tests). Please uncheck "Needs tests" if you can update
it, thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:6>
* owner: nobody => nip3o
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:7>
* has_patch: 0 => 1
* needs_tests: 1 => 0
Comment:
New PR with the existing patch applied and including test cases.
https://github.com/django/django/pull/2964
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"cdc25ac4747bf5a6cdc2e70461c2d43c54529d35"]:
{{{
#!CommitTicketReference repository=""
revision="cdc25ac4747bf5a6cdc2e70461c2d43c54529d35"
Fixed #22808 -- Made ModelMultipleChoiceField validation more robust to
invalid data types..
Thanks Mattias Lindvall for the report and inital patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22808#comment:9>