mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
[4.2.x] Fixed #34346 -- Ordered selected expressions by position.
Used the same approach as for #34176 by using selected expressions position to prevent ambiguous aliases in collisions. Thanks henribru for the report. Regression in04518e310d. Backport of278881e376from main
This commit is contained in:
committed by
Mariusz Felisiak
parent
312d0f88b4
commit
aab25a69dd
@@ -8,6 +8,7 @@ from django.db.models import (
|
||||
DateTimeField,
|
||||
F,
|
||||
Max,
|
||||
OrderBy,
|
||||
OuterRef,
|
||||
Subquery,
|
||||
Value,
|
||||
@@ -619,3 +620,21 @@ class OrderingTests(TestCase):
|
||||
),
|
||||
Author.objects.order_by(Length(Upper("name"))),
|
||||
)
|
||||
|
||||
def test_ordering_select_related_collision(self):
|
||||
self.assertEqual(
|
||||
Article.objects.select_related("author")
|
||||
.annotate(name=Upper("author__name"))
|
||||
.filter(pk=self.a1.pk)
|
||||
.order_by(OrderBy(F("name")))
|
||||
.first(),
|
||||
self.a1,
|
||||
)
|
||||
self.assertEqual(
|
||||
Article.objects.select_related("author")
|
||||
.annotate(name=Upper("author__name"))
|
||||
.filter(pk=self.a1.pk)
|
||||
.order_by("name")
|
||||
.first(),
|
||||
self.a1,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user