#26433: Bug: annotating using When(id__in=[], ...) returns empty queryset
----------------------------------------------+--------------------
     Reporter:  kevinmarsh                    |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.9
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 {{{
 qs = MyModel.objects.all().annotate(
     field=models.Case(
         models.When(id__in=[], then=models.Value(True)),
         default=models.Value(False),
         output_field=models.BooleanField()
     )
 )
 }}}

 This results in slightly inconsistent behaviour, `qs` is an empty queryset
 (irregardless of how many items are in the original queryset ''before''
 annotating) and calling `qs.count` will always return `0`. However calling
 `str(qs.query)` raises `EmptyResultSet` which is presumably the correct
 behaviour?

 I've attached a failing test better showcasing this.

--
Ticket URL: <https://code.djangoproject.com/ticket/26433>
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/053.c5a8e0919197770002f5e0eeea640156%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to