id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 25307,Cannot use .annotate with conditional expressions,Jared Proffitt,nobody,"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.",Bug,closed,"Database layer (models, ORM)",dev,Normal,fixed,,josh.smeaton@… matt@… Simon Charette newport.travis@…,Ready for checkin,1,0,0,1,0,0