[2.2.x] Fixed #30463 -- Fixed crash of deprecation message when Meta.ordering contains expressions.
Regression in1b1f64ee5a
. Backport of04042b2b44
from master
This commit is contained in:
parent
ed221f7c97
commit
db7d7901ee
|
@ -561,9 +561,9 @@ class SQLCompiler:
|
||||||
# order_by = None
|
# order_by = None
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"%s QuerySet won't use Meta.ordering in Django 3.1. "
|
"%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__,
|
self.query.model.__name__,
|
||||||
"', '".join(self._meta_ordering)
|
', '.join(repr(f) for f in self._meta_ordering),
|
||||||
),
|
),
|
||||||
RemovedInDjango31Warning,
|
RemovedInDjango31Warning,
|
||||||
stacklevel=4,
|
stacklevel=4,
|
||||||
|
|
|
@ -11,3 +11,6 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed a regression in Django 2.2 that stopped Show/Hide toggles working on
|
* Fixed a regression in Django 2.2 that stopped Show/Hide toggles working on
|
||||||
dynamically added admin inlines (:ticket:`30459`).
|
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`).
|
||||||
|
|
|
@ -14,6 +14,7 @@ undefined -- not random, just undefined.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models.expressions import OrderBy
|
||||||
|
|
||||||
|
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
|
@ -30,7 +31,12 @@ class Article(models.Model):
|
||||||
pub_date = models.DateTimeField()
|
pub_date = models.DateTimeField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('-pub_date', 'headline')
|
ordering = (
|
||||||
|
'-pub_date',
|
||||||
|
'headline',
|
||||||
|
models.F('author__name').asc(),
|
||||||
|
OrderBy(models.F('second_author__name')),
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
|
|
|
@ -408,7 +408,9 @@ class OrderingTests(TestCase):
|
||||||
def test_deprecated_values_annotate(self):
|
def test_deprecated_values_annotate(self):
|
||||||
msg = (
|
msg = (
|
||||||
"Article QuerySet won't use Meta.ordering in Django 3.1. Add "
|
"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):
|
with self.assertRaisesMessage(RemovedInDjango31Warning, msg):
|
||||||
list(Article.objects.values('author').annotate(Count('headline')))
|
list(Article.objects.values('author').annotate(Count('headline')))
|
||||||
|
|
Loading…
Reference in New Issue