#34449: ProgrammingError: non-integer constant in GROUP BY with Case When and
annotate Count
-------------------------------------+-------------------------------------
Reporter: Guillaume LEBRETON | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):
Hi, thanks for the report but I can't reproduce this on latest main or 4.1
using the example supplied. Inspecting the queryset shows that Django is
correctly using the column number for the alarm annotation:
{{{
qs = Person.objects.all().annotate(number=Count("quantitativeattribute"))
qs = qs.annotate(
alarm=Case(
When(id__in=[], then=Value("danger", output_field=CharField())),
default=Value("warning"),
)
)
qs = qs.values("pk", "number", "alarm")
print(qs.query)
}}}
result:
{{{
SELECT "ticket_34449_person"."id",
COUNT("ticket_34449_quantitativeattribute"."id") AS "number", warning AS
"alarm" FROM "ticket_34449_person" LEFT OUTER JOIN
"ticket_34449_quantitativeattribute" ON ("ticket_34449_person"."id" =
"ticket_34449_quantitativeattribute"."person_id") GROUP BY
"ticket_34449_person"."id", 3
}}}
Maybe double check the supplied example isn't leaving anything out? 🤔
--
Ticket URL: <https://code.djangoproject.com/ticket/34449#comment:1>
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/01070187333b29b9-d92b884d-28e9-4e98-a177-804471ed2163-000000%40eu-central-1.amazonses.com.