﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36065	"order_by(""pk"") not equivalent to order_by(F(""pk"")) for CompositePrimaryKey"	Jacob Walls	Simon Charette	"For CompositePrimaryKey, `order_by(""pk"")` and `order_by(F(""pk""))` produce different results.

For `""pk""`, direction is distributed to all cols `(col1 ASC, col2 ASC)`, but for `F(""pk"")`, it is not: `(col1, col2 ASC)`.

Failing test:
{{{#!diff
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py
index 7e361c5925..81bbfc65be 100644
--- a/tests/composite_pk/test_filter.py
+++ b/tests/composite_pk/test_filter.py
@@ -1,3 +1,4 @@
+from django.db.models import F
 from django.test import TestCase
 
 from .models import Comment, Tenant, User
@@ -78,6 +79,12 @@ class CompositePKFilterTests(TestCase):
             ),
         )
 
+    def test_order_by_comments_by_pk_asc_f(self):
+        self.assertSequenceEqual(
+            Comment.objects.order_by(""pk""),
+            Comment.objects.order_by(F(""pk"")),
+        )
+
     def test_filter_comments_by_pk_gt(self):
         c11, c12, c13, c24, c15 = (
             self.comment_1,
}}}
{{{
======================================================================
FAIL: test_order_by_comments_by_pk_asc_f (composite_pk.test_filter.CompositePKFilterTests.test_order_by_comments_by_pk_asc_f)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/user/django/tests/composite_pk/test_filter.py"", line 83, in test_order_by_comments_by_pk_asc_f
    self.assertSequenceEqual(
AssertionError: Sequences differ: <Quer[123 chars] Comment object ((1, 5))>, <Comment: Comment object ((2, 4))>]> != <Quer[123 chars] Comment object ((1, 5))>, <Comment: Comment object ((2, 4))>]>

  <QuerySet [<Comment: Comment object ((1, 1))>, <Comment: Comment object ((1, 2))>, <Comment: Comment object ((1, 3))>, <Comment: Comment object ((1, 5))>, <Comment: Comment object ((2, 4))>]>

----------------------------------------------------------------------
(0.000)
SELECT ""composite_pk_comment"".""tenant_id"",
       ""composite_pk_comment"".""comment_id"",
       ""composite_pk_comment"".""user_id"",
       ""composite_pk_comment"".""text""
FROM ""composite_pk_comment""
ORDER BY ""composite_pk_comment"".""tenant_id"" ASC,
         ""composite_pk_comment"".""comment_id"" ASC;

args=();

ALIAS=DEFAULT (0.000)
SELECT ""composite_pk_comment"".""tenant_id"",
       ""composite_pk_comment"".""comment_id"",
       ""composite_pk_comment"".""user_id"",
       ""composite_pk_comment"".""text""
FROM ""composite_pk_comment""
ORDER BY ""composite_pk_comment"".""tenant_id"",
         ""composite_pk_comment"".""comment_id"" ASC;

args=();

ALIAS=DEFAULT
----------------------------------------------------------------------
Ran 103 tests in 0.107s

FAILED (failures=1)
}}}"	Bug	closed	Database layer (models, ORM)	dev	Release blocker	fixed		Csirmaz Bendegúz	Ready for checkin	1	0	0	0	0	0
