#35235: ArrayAgg() doesn't return default when filter contains __in=[].
----------------------------------+--------------------------------------
     Reporter:  Per Carlsen       |                    Owner:  Sharon Woo
         Type:  Bug               |                   Status:  assigned
    Component:  contrib.postgres  |                  Version:  5.0
     Severity:  Normal            |               Resolution:
     Keywords:  ArrayAgg          |             Triage Stage:  Accepted
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

 * cc: Simon Charette, Nick Pope (added)
 * stage:  Unreviewed => Accepted
 * summary:  ArrayAgg inconsistent return value when no results =>
     ArrayAgg() doesn't return default when filter contains __in=[].

Comment:

 I was able to reproduce the issue with a small models:
 {{{#!python
 class MyModel(models.Model):
     pass


 class MyOtherModel(models.Model):
     mymodel = models.ForeignKey(MyModel, models.CASCADE)

 for filter_value in ([], [-1]):
     for default in ([], Value([])):
         result = MyModel.objects.annotate(
             annotated_ids=ArrayAgg(
                 "myothermodel__id",
                 filter=Q(
                     myothermodel__id__in=filter_value,
                 ),
                 default=Value([]),
             )
         ).first().annotated_ids
         print(result, filter_value, default)

 }}}
 results
 {{{
 {} [] []
 {} [] Value([])
 [] [-1] []
 [] [-1] Value([])
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35235#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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018dc5acf92d-daa82adf-4aaf-4cd3-a253-fc61142d9a73-000000%40eu-central-1.amazonses.com.

Reply via email to