Changes between Version 2 and Version 3 of Ticket #25980


Ignore:
Timestamp:
Dec 23, 2015, 1:09:02 PM (9 years ago)
Author:
karyon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25980

    • Property Summary Inconsistent error behaviour when providing a queryset as initial value on ModelMultipleChoiceFieldWrong handling of initial value on disabled ModelMultipleChoiceField
  • Ticket #25980 – Description

    v2 v3  
    33but, when saving the form i got an error  {{{ Enter a list of values.}}}
    44
    5 1. the error did not show up when the queryset i provided yielded no results, which is inconsistent. the reason for that is that [https://github.com/django/django/blob/d91cc25a2a43cb2526943dc2285ffe59e38fabfd/django/forms/models.py#L1250 this boolean expression] evaluates to true as soon as there are results in the queryset.
     51. this happens because disabled fields send their initial value to cleaning, see [[https://github.com/django/django/blob/d91cc25a2a43cb2526943dc2285ffe59e38fabfd/django/forms/forms.py#L372 here]. in case of model fields, it looks like this must be a list of PKs, which is quite unhandy to build (something like {{{list(queryset.values_list('pk', flat=True))}}})
     62. the error did not show up when the queryset i provided yielded no results, which is inconsistent. the reason for that is that [https://github.com/django/django/blob/d91cc25a2a43cb2526943dc2285ffe59e38fabfd/django/forms/models.py#L1250 this boolean expression] evaluates to true as soon as there are results in the queryset.
    67
    7 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 [https://github.com/django/django/blob/d91cc25a2a43cb2526943dc2285ffe59e38fabfd/django/forms/forms.py#L372 here]
    8 
    9 2. 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.
     83. something else appeared fishy to me: in one line the clean 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.
    109
    1110if you folks tell me what the intended behaviour is / which types should be used, i can try to create a fix if you want.
    1211
    13 3. 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.
     124. 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.
Back to Top