1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #36065 -- Fixed ordering by expression referencing composite primary key.

Thanks Jacob Walls for the report and test and Csirmaz Bendegúz for the review.
This commit is contained in:
Simon Charette
2025-01-07 00:02:31 -05:00
committed by Sarah Boyce
parent 7617d5be94
commit 42e8f264ce
3 changed files with 26 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
from django.db.models import F
from django.test import TestCase
from .models import Comment, Tenant, User
@@ -55,3 +56,17 @@ class CompositePKOrderByTests(TestCase):
self.comment_1, # (1, 1)
),
)
def test_order_comments_by_pk_expr(self):
self.assertQuerySetEqual(
Comment.objects.order_by("pk"),
Comment.objects.order_by(F("pk")),
)
self.assertQuerySetEqual(
Comment.objects.order_by("-pk"),
Comment.objects.order_by(F("pk").desc()),
)
self.assertQuerySetEqual(
Comment.objects.order_by("-pk"),
Comment.objects.order_by(F("pk").desc(nulls_last=True)),
)