Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #30463 -- Fixed crash of deprecation message when Meta.ordering contains expressions. #11377

Merged
merged 1 commit into from May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions django/db/models/sql/compiler.py
Expand Up @@ -553,9 +553,9 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
# order_by = None
warnings.warn(
"%s QuerySet won't use Meta.ordering in Django 3.1. "
"Add .order_by('%s') to retain the current query." % (
"Add .order_by(%s) to retain the current query." % (
self.query.model.__name__,
"', '".join(self._meta_ordering)
', '.join(repr(f) for f in self._meta_ordering),
),
RemovedInDjango31Warning,
stacklevel=4,
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/2.2.2.txt
Expand Up @@ -11,3 +11,6 @@ Bugfixes

* Fixed a regression in Django 2.2 that stopped Show/Hide toggles working on
dynamically added admin inlines (:ticket:`30459`).

* Fixed a regression in Django 2.2 where deprecation message crashes if
``Meta.ordering`` contains an expression (:ticket:`30463`).
8 changes: 7 additions & 1 deletion tests/ordering/models.py
Expand Up @@ -14,6 +14,7 @@
"""

from django.db import models
from django.db.models.expressions import OrderBy


class Author(models.Model):
Expand All @@ -30,7 +31,12 @@ class Article(models.Model):
pub_date = models.DateTimeField()

class Meta:
ordering = ('-pub_date', 'headline')
ordering = (
'-pub_date',
'headline',
models.F('author__name').asc(),
OrderBy(models.F('second_author__name')),
)

def __str__(self):
return self.headline
Expand Down
4 changes: 3 additions & 1 deletion tests/ordering/tests.py
Expand Up @@ -408,7 +408,9 @@ def test_default_ordering_by_f_expression(self):
def test_deprecated_values_annotate(self):
msg = (
"Article QuerySet won't use Meta.ordering in Django 3.1. Add "
".order_by('-pub_date', 'headline') to retain the current query."
".order_by('-pub_date', 'headline', OrderBy(F(author__name), "
"descending=False), OrderBy(F(second_author__name), "
"descending=False)) to retain the current query."
)
with self.assertRaisesMessage(RemovedInDjango31Warning, msg):
list(Article.objects.values('author').annotate(Count('headline')))