From 42e8f264ce55710056b0033682ec6fd662a25b29 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 7 Jan 2025 00:02:31 -0500 Subject: Fixed #36065 -- Fixed ordering by expression referencing composite primary key. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Jacob Walls for the report and test and Csirmaz Bendegúz for the review. --- tests/composite_pk/test_order_by.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/composite_pk/test_order_by.py b/tests/composite_pk/test_order_by.py index 9d3dec58e7..f17d6b55e4 100644 --- a/tests/composite_pk/test_order_by.py +++ b/tests/composite_pk/test_order_by.py @@ -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)), + ) -- cgit v1.3