#32200: Aggregating when grouping on an ExpressionWrapper omits the expression from the group by ------------------------------------------+------------------------ Reporter: Gordon Wrigley | Owner: nobody Type: Uncategorized | Status: new Component: Uncategorized | Version: 3.1 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | ------------------------------------------+------------------------ I ran into this with Postgres on Django 3.1.3, I'm not sure what other versions it exists on.
{{{ #!python print( Fred.objects.annotate( bob_id__is_null=ExpressionWrapper( Q(bob_id=None), output_field=BooleanField() ) ).values( "bob_id__is_null" ).annotate( id__count=Count("id", distinct=True) ).values( "bob_id__is_null", "id__count" ).query ) }}} {{{ #!sql SELECT "main_fred"."bob_id" IS NULL AS "bob_id__is_null", COUNT(DISTINCT "main_fred"."id") AS "id__count" FROM "main_fred" GROUP BY "main_fred"."bob_id" }}} On the last line there the group by has dropped the "IS NULL" -- Ticket URL: <https://code.djangoproject.com/ticket/32200> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.20ae340c15e3cb9809f12c83034ac0f9%40djangoproject.com.