#25307: Cannot use .annotate with conditional expressions
----------------------------------------------+--------------------
Reporter: jproffitt | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I am trying to create a query that first annotates a `Count`, then
aggregates some `Sum`s together using `Case` objects. If I do the query
without the annotate, everything is fine. If I do the query without any
`Case` objects in the aggregate, everything is fine. But when they are
both present I get this error:
{{{
'WhereNode' object has no attribute 'get_source_expressions'
}}}
My query is something like this:
{{{
counts = models.Package.objects.annotate(
used_count=Count('projects')
).distinct().aggregate(
no_parent=Sum(Case(
When(parent_id__isnull=True, then=1),
default=0,
output_field=IntegerField()
))
)
}}}
I would like to eventually add the `used_count` value in the aggregate,
but this itself won't even run.
--
Ticket URL: <https://code.djangoproject.com/ticket/25307>
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/052.4631d6c5f86a2d3b9ec12c2fb79d0ace%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.