#23557: Prevent silent extension of explicit GROUP BY when using order_by -------------------------------------+------------------------------------- Reporter: Brian May | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.7 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Simon Charette): I'll note that the issue initially reported issue here is not reproducible anymore since #14357 which deprecated `Meta.ordering` from being considered when doing annotation. Even if that was not the case the optimization of selected primary key grouping in #19259 would also have solve the I still think that it would be worth to keep this ticket open though to go through a deprecation period and then raise an error when `values` is used for grouping and is paired with an explicit `order_by` that would result in extra `GROUP BY` entries. This can likely be achieved in [https://github.com/django/django/blob/897f38fabea5e1b196f11250ff6dadfffa489840/django/db/models/sql/compiler.py#L149-L154 SQLCompiler.get_group_by] by branching off `self.query.group_by is not True` and comparing the results of calling `self.collapse_group_by` with expressions originating from `order_by` and ones without and if there is any difference warn/raise. -- Ticket URL: <https://code.djangoproject.com/ticket/23557#comment:8> 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/01070182ce2ff604-ea3791ab-b1af-49bf-a4f2-5d715dc96c40-000000%40eu-central-1.amazonses.com.