Refs #14357 -- Deprecated Meta.ordering affecting GROUP BY queries.

Thanks Ramiro Morales for contributing to the patch.
This commit is contained in:
Ramiro Morales 2018-09-13 13:29:48 -03:00 committed by Tim Graham
parent c52ecbda61
commit 1b1f64ee5a
9 changed files with 80 additions and 16 deletions

View file

@ -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

View file

@ -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
<aggregation-ordering-interaction>`.
<aggregation-ordering-interaction>` but this won't be the case starting
in Django 3.1.
.. warning::

View file

@ -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
-------------

View file

@ -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()``