Skip to content

Commit

Permalink
[2.2.x] Fixed #30463 -- Fixed crash of deprecation message when Meta.…
Browse files Browse the repository at this point in the history
…ordering contains expressions.

Regression in 1b1f64e.

Backport of 04042b2 from master
  • Loading branch information
ruchit2801 authored and felixxm committed May 18, 2019
1 parent ed221f7 commit db7d790
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/db/models/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')))

0 comments on commit db7d790

Please sign in to comment.