mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #30557 -- Fixed crash of ordering by ptr fields when Meta.ordering contains F() expressions.
Thanks Can Sarıgöl for the report.
Follow up to 8c5f9906c5
.
This commit is contained in:
parent
8c5f9906c5
commit
7a42cfcfdc
@ -722,6 +722,8 @@ class SQLCompiler:
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
for item in opts.ordering:
|
for item in opts.ordering:
|
||||||
|
if hasattr(item, 'resolve_expression') and not isinstance(item, OrderBy):
|
||||||
|
item = item.desc() if descending else item.asc()
|
||||||
if isinstance(item, OrderBy):
|
if isinstance(item, OrderBy):
|
||||||
results.append((item, False))
|
results.append((item, False))
|
||||||
continue
|
continue
|
||||||
|
@ -33,7 +33,7 @@ class Article(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = (
|
ordering = (
|
||||||
'-pub_date',
|
'-pub_date',
|
||||||
'headline',
|
models.F('headline'),
|
||||||
models.F('author__name').asc(),
|
models.F('author__name').asc(),
|
||||||
OrderBy(models.F('second_author__name')),
|
OrderBy(models.F('second_author__name')),
|
||||||
)
|
)
|
||||||
|
@ -485,7 +485,7 @@ 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', OrderBy(F(author__name), "
|
".order_by('-pub_date', F(headline), OrderBy(F(author__name), "
|
||||||
"descending=False), OrderBy(F(second_author__name), "
|
"descending=False), OrderBy(F(second_author__name), "
|
||||||
"descending=False)) to retain the current query."
|
"descending=False)) to retain the current query."
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user