Opened 9 years ago

Last modified 9 years ago

#25980 new Bug

Inconsistent error behaviour when providing a queryset as initial value on ModelMultipleChoiceField — at Version 2

Reported by: karyon Owned by: nobody
Component: Forms Version: 1.9
Severity: Normal Keywords:
Cc: johannes.linke@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by karyon)

So i provided a queryset as initial value for a non-required and disabled ModelMultipleChoiceField. it seemed to work as i saw the correct values in the rendered output.

but, when saving the form i got an error Enter a list of values.

  1. the error did not show up when the queryset i provided yielded no results, which is inconsistent. the reason for that is that this boolean expression evaluates to true as soon as there are results in the queryset.

edit: just found out this can only happen for disabled fields, because there the initial value is cleaned, and not some value taken from the widget, see here

  1. something else appeared fishy to me: in one line this method returns a queryset (self.queryset.none()), but in the next line it raises an error if the value is neither a list nor a tuple.

if you folks tell me what the intended behaviour is / which types should be used, i can try to create a fix if you want.

  1. and the last (slightly unrelated) issue: since the field was disabled, i was wondering why cleaning it doesn't take a shortcut and does nothing at all... bumped into this a few times.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (2)

comment:1 by karyon, 9 years ago

Cc: johannes.linke@… added

comment:2 by karyon, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top