From 1b1f64ee5a78cc217fead52cbae23114502cf564 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Thu, 13 Sep 2018 13:29:48 -0300 Subject: Refs #14357 -- Deprecated Meta.ordering affecting GROUP BY queries. Thanks Ramiro Morales for contributing to the patch. --- docs/internals/deprecation.txt | 2 ++ docs/ref/models/options.txt | 3 ++- docs/releases/2.2.txt | 9 +++++++++ docs/topics/db/aggregation.txt | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index d7b02fa3bc..7043391527 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -19,6 +19,8 @@ details on these changes. * ``django.core.paginator.QuerySetPaginator`` will be removed. +* A model's ``Meta.ordering`` will no longer affect ``GROUP BY`` queries. + .. _deprecation-removed-in-3.0: 3.0 diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index 246f3e7d9a..3994e408a5 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -285,7 +285,8 @@ Django quotes column and table names behind the scenes. ordering = [F('author').asc(nulls_last=True)] Default ordering also affects :ref:`aggregation queries - `. + ` but this won't be the case starting + in Django 3.1. .. warning:: diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index af2910a514..bf5bc30cde 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -289,6 +289,15 @@ Miscellaneous Features deprecated in 2.2 ========================== +Model ``Meta.ordering`` will no longer affect ``GROUP BY`` queries +------------------------------------------------------------------ + +A model's ``Meta.ordering`` affecting ``GROUP BY`` queries (such as +``.annotate().values()``) is a common source of confusion. Such queries now +issue a deprecation warning with the advice to add an ``order_by()`` to retain +the current query. ``Meta.ordering`` will be ignored in such queries starting +in Django 3.1. + Miscellaneous ------------- diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt index 50a92a5dbe..c709c064a5 100644 --- a/docs/topics/db/aggregation.txt +++ b/docs/topics/db/aggregation.txt @@ -514,6 +514,13 @@ include the aggregate column. Interaction with default ordering or ``order_by()`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. deprecated:: 2.2 + + Starting in Django 3.1, the ordering from a model's ``Meta.ordering`` won't + be used in ``GROUP BY`` queries, such as ``.annotate().values()``. Since + Django 2.2, these queries issue a deprecation warning indicating to add an + explicit ``order_by()`` to the queryset to silence the warning. + Fields that are mentioned in the ``order_by()`` part of a queryset (or which are used in the default ordering on a model) are used when selecting the output data, even if they are not otherwise specified in the ``values()`` -- cgit v1.3