It seems that using an empty list when using the `__in=` filter prevents an 
Aggregate Coalesce from working properly. See below:

# Test with matched Queryset. Sum will return 50
OrderItem.objects.filter(pk__in=[1]).aggregate(test=Coalesce(Sum('quantity'), 
Value(0)))
>>> {'test': 50}
 
# Test with unmatched Queryset. Sum will return 0
OrderItem.objects.filter(pk__in=[-1]).aggregate(test=Coalesce(Sum('quantity'), 
Value(0)))
>>> {'test':0}
 
# Test with unmatched Queryset (using empty list). Sum will return NONE
OrderItem.objects.filter(pk__in=[]).aggregate(test=Coalesce(Sum('quantity'), 
Value(0)))
>>> {'test': None}

Can someone confirm? I will post as a bug if so.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fee905a3-5530-4fd9-9994-85447062665c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to