#30000: Passing QuerySet constructed with .union() causes 
ModelMultipleChoiceField
to return wrong values
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Forms                |                  Version:  1.11
     Severity:  Normal               |               Resolution:
     Keywords:  queryset, union,     |             Triage Stage:
  forms                              |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by thoha):

 After some further testing it appears the unexpected behaviour comes from
 the fact that UNION querysets cannot be filtered, which the
 ModelMultipleChoiceField apparently does out of sight. Still, I believe
 that the observed behaviour is undesired, and the field should either
 accept the union queryset and work properly, or raise an exception if a
 union queryset is passed.

 I also found that using

 {{{
 union_queryset =
 
SelectableRecords.objects.filter(other_related_thing_name__in=other_related_things)
 }}}

 instead of the for-loop results in a queryset that actually works properly
 with the ModelMultipleChoiceField. Based on
 [https://stackoverflow.com/questions/50638442/django-queryset-union-
 return-broken-queryset-filter-and-get-return-every this StackOverflow
 question].

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30000#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.f9e6fa2fbc30e72932f955d8ff27f494%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to