1
0
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 in 04518e310d.

Backport of 278881e376 from main
This commit is contained in:
Simon Charette
2023-02-17 20:38:08 -05:00
committed by Mariusz Felisiak
parent 312d0f88b4
commit aab25a69dd
3 changed files with 55 additions and 10 deletions

View File

@@ -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,
)