#30246: Using an annotated field calculated with django.db.models.functions.Extract in aggregate results in ProgrammingError -------------------------------------+------------------------------------- Reporter: Jan BaryĆa | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 2.1 (models, ORM) | Severity: Normal | Resolution: Keywords: query, aggregate, | Triage Stage: extract, annotate | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Simon Charette): Hello Jan, thank you for your report. Just a few questions. You said the code worked fine on 1.8 but the `Aggregate(filter)` argument [https://docs.djangoproject.com/en/2.1/topics/db/aggregation/#filtering- on-annotations was only introduced in Django 2.0] and the `Extact` function [https://docs.djangoproject.com/en/1.10/ref/models/database- functions/ was only added in Django 1.10]. Were you using an explicit `Case(When(...))` in Django 1.8? Does using a `Case(When(...))` on Django 2.1 happens to work around the issue? If not could you try to [https://docs.djangoproject.com/en/2.1/internals/contributing/triaging- tickets/#bisecting-a-regression bisect the change that broke it]. You said you tried against 2.1 but did you try against the [https://pypi.org/project/Django/2.2b1/ current 2.2 beta as well]? Finally I think your misunderstood how to force the ORM to perform group by. I think what you are after is something along the lines of {{{#!python MyModel.objects.values('usage_time__hour').annotate(Sum('usage')) }}} And perform the hour labeling on the python side. -- Ticket URL: <https://code.djangoproject.com/ticket/30246#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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.891d68db93bb788c2e21358b8329477b%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.