{"action":"created","comment":{"url":"https://api.github.com/repos/django/django/pulls/comments/200827895","pull_request_review_id":135220354,"id":200827895,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMDgyNzg5NQ==","diff_hunk":"@@ -0,0 +1,131 @@\n+from unittest import mock, skip\n+from operator import attrgetter\n+\n+from django.test import TestCase\n+from django.db import models\n+\n+from .models import Musician, Album, Song\n+\n+\n+class OrderWithExpressionTests(TestCase):\n+\n+    @classmethod\n+    def setUpTestData(cls):\n+        cls.musician1 = Musician.objects.create(instrument='mayonaise')\n+        cls.musician3 = Musician.objects.create(instrument=None)\n+        cls.musician2 = Musician.objects.create(instrument='zoo')\n+\n+        cls.album1 = Album.objects.create(\n+            artist=cls.musician1,\n+            name='Album 1',\n+        )\n+        cls.album3 = Album.objects.create(\n+            artist=cls.musician3,\n+            name='Album 3',\n+        )\n+        cls.album2 = Album.objects.create(\n+            artist=cls.musician2,\n+            name='Album 2',\n+        )\n+\n+        cls.song1 = Song.objects.create(\n+            album=cls.album1,\n+            name='Song 1',\n+        )\n+        cls.song3 = Song.objects.create(\n+            album=cls.album3,\n+            name='Song 3',\n+        )\n+        cls.song2 = Song.objects.create(\n+            album=cls.album2,\n+            name='Song 2',\n+        )\n+\n+    def test_order_by_expression_nulls_last(self):\n+        self.assertQuerysetEqual(\n+            Musician.objects.all(),\n+            ['mayonaise', 'zoo', None],\n+            attrgetter('instrument')\n+        )\n+\n+    def test_order_by_related_expression_nulls_last(self):\n+        self.assertQuerysetEqual(\n+            Album.objects.all(),\n+            ['Album 1', 'Album 2', 'Album 3'],\n+            attrgetter('name')\n+        )\n+\n+    def test_order_by_related_expression_through_related_field_nulls_last(self):\n+        self.assertQuerysetEqual(\n+            Song.objects.all(),\n+            ['Song 1', 'Song 2', 'Song 3'],\n+            attrgetter('name')\n+        )\n+\n+    def test_order_by_expression_nulls_first(self):\n+\n+        ordering = [models.F('instrument').asc(nulls_first=True)]\n+\n+        with mock.patch.object(Musician._meta, 'ordering', ordering):\n+            self.assertQuerysetEqual(\n+                Musician.objects.all(),\n+                [None, 'mayonaise', 'zoo'],\n+                attrgetter('instrument')\n+            )\n+\n+    def test_order_by_related_expression_nulls_first(self):\n+\n+        ordering = [models.F('instrument').asc(nulls_first=True)]\n+\n+        with mock.patch.object(Musician._meta, 'ordering', ordering):\n+            self.assertQuerysetEqual(\n+                Album.objects.all(),\n+                ['Album 3', 'Album 1', 'Album 2'],\n+                attrgetter('name')\n+            )\n+\n+    def test_depth_3_nulls_first(self):\n+\n+        ordering = [models.F('instrument').asc(nulls_first=True)]\n+\n+        with mock.patch.object(Musician._meta, 'ordering', ordering):\n+            self.assertQuerysetEqual(\n+                Song.objects.all(),\n+                ['Song 3', 'Song 1', 'Song 2'],\n+                attrgetter('name')\n+            )\n+\n+    @skip('What should the behavior be?')","path":"tests/order_with_expression/tests.py","position":98,"original_position":98,"commit_id":"093df8f0ac206fec6efd01d13c12fe7035899e51","original_commit_id":"093df8f0ac206fec6efd01d13c12fe7035899e51","user":{"login":"alexandrelaplante","id":215647,"node_id":"MDQ6VXNlcjIxNTY0Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/215647?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrelaplante","html_url":"https://github.com/alexandrelaplante","followers_url":"https://api.github.com/users/alexandrelaplante/followers","following_url":"https://api.github.com/users/alexandrelaplante/following{/other_user}","gists_url":"https://api.github.com/users/alexandrelaplante/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrelaplante/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrelaplante/subscriptions","organizations_url":"https://api.github.com/users/alexandrelaplante/orgs","repos_url":"https://api.github.com/users/alexandrelaplante/repos","events_url":"https://api.github.com/users/alexandrelaplante/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrelaplante/received_events","type":"User","site_admin":false},"body":"Not sure what the expected behavior here is.\r\n\r\n```python\r\nclass Album:\r\n    class Meta:\r\n        # Should both of these work the same way? Or does\r\n        # The first mean \"order by artist_id\"\r\n        # And the second mean, order by the default order of Musician?\r\n        ordering = [models.F('artist').asc(nulls_last=True)]\r\n        ordering = ['artist']\r\n```","created_at":"2018-07-08T02:48:32Z","updated_at":"2018-07-08T02:48:32Z","html_url":"https://github.com/django/django/pull/10146#discussion_r200827895","pull_request_url":"https://api.github.com/repos/django/django/pulls/10146","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/comments/200827895"},"html":{"href":"https://github.com/django/django/pull/10146#discussion_r200827895"},"pull_request":{"href":"https://api.github.com/repos/django/django/pulls/10146"}}},"pull_request":{"url":"https://api.github.com/repos/django/django/pulls/10146","id":199922407,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5OTIyNDA3","html_url":"https://github.com/django/django/pull/10146","diff_url":"https://github.com/django/django/pull/10146.diff","patch_url":"https://github.com/django/django/pull/10146.patch","issue_url":"https://api.github.com/repos/django/django/issues/10146","number":10146,"state":"open","locked":false,"title":"WIP: Fixed #29538 -- Query Expression in ordering of a related object fails","user":{"login":"alexandrelaplante","id":215647,"node_id":"MDQ6VXNlcjIxNTY0Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/215647?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrelaplante","html_url":"https://github.com/alexandrelaplante","followers_url":"https://api.github.com/users/alexandrelaplante/followers","following_url":"https://api.github.com/users/alexandrelaplante/following{/other_user}","gists_url":"https://api.github.com/users/alexandrelaplante/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrelaplante/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrelaplante/subscriptions","organizations_url":"https://api.github.com/users/alexandrelaplante/orgs","repos_url":"https://api.github.com/users/alexandrelaplante/repos","events_url":"https://api.github.com/users/alexandrelaplante/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrelaplante/received_events","type":"User","site_admin":false},"body":"Added support for ordering related objects by query expressions","created_at":"2018-07-08T02:45:05Z","updated_at":"2018-07-08T02:48:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49c6cbd60347feca9140c56b43d0925fa09e60cb","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/django/django/pulls/10146/commits","review_comments_url":"https://api.github.com/repos/django/django/pulls/10146/comments","review_comment_url":"https://api.github.com/repos/django/django/pulls/comments{/number}","comments_url":"https://api.github.com/repos/django/django/issues/10146/comments","statuses_url":"https://api.github.com/repos/django/django/statuses/093df8f0ac206fec6efd01d13c12fe7035899e51","head":{"label":"alexandrelaplante:al/fix-order-by-related-query-expression","ref":"al/fix-order-by-related-query-expression","sha":"093df8f0ac206fec6efd01d13c12fe7035899e51","user":{"login":"alexandrelaplante","id":215647,"node_id":"MDQ6VXNlcjIxNTY0Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/215647?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrelaplante","html_url":"https://github.com/alexandrelaplante","followers_url":"https://api.github.com/users/alexandrelaplante/followers","following_url":"https://api.github.com/users/alexandrelaplante/following{/other_user}","gists_url":"https://api.github.com/users/alexandrelaplante/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrelaplante/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrelaplante/subscriptions","organizations_url":"https://api.github.com/users/alexandrelaplante/orgs","repos_url":"https://api.github.com/users/alexandrelaplante/repos","events_url":"https://api.github.com/users/alexandrelaplante/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrelaplante/received_events","type":"User","site_admin":false},"repo":{"id":140099616,"node_id":"MDEwOlJlcG9zaXRvcnkxNDAwOTk2MTY=","name":"django","full_name":"alexandrelaplante/django","owner":{"login":"alexandrelaplante","id":215647,"node_id":"MDQ6VXNlcjIxNTY0Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/215647?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrelaplante","html_url":"https://github.com/alexandrelaplante","followers_url":"https://api.github.com/users/alexandrelaplante/followers","following_url":"https://api.github.com/users/alexandrelaplante/following{/other_user}","gists_url":"https://api.github.com/users/alexandrelaplante/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrelaplante/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrelaplante/subscriptions","organizations_url":"https://api.github.com/users/alexandrelaplante/orgs","repos_url":"https://api.github.com/users/alexandrelaplante/repos","events_url":"https://api.github.com/users/alexandrelaplante/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrelaplante/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexandrelaplante/django","description":"The Web framework for perfectionists with deadlines.","fork":true,"url":"https://api.github.com/repos/alexandrelaplante/django","forks_url":"https://api.github.com/repos/alexandrelaplante/django/forks","keys_url":"https://api.github.com/repos/alexandrelaplante/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexandrelaplante/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexandrelaplante/django/teams","hooks_url":"https://api.github.com/repos/alexandrelaplante/django/hooks","issue_events_url":"https://api.github.com/repos/alexandrelaplante/django/issues/events{/number}","events_url":"https://api.github.com/repos/alexandrelaplante/django/events","assignees_url":"https://api.github.com/repos/alexandrelaplante/django/assignees{/user}","branches_url":"https://api.github.com/repos/alexandrelaplante/django/branches{/branch}","tags_url":"https://api.github.com/repos/alexandrelaplante/django/tags","blobs_url":"https://api.github.com/repos/alexandrelaplante/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexandrelaplante/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexandrelaplante/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexandrelaplante/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexandrelaplante/django/statuses/{sha}","languages_url":"https://api.github.com/repos/alexandrelaplante/django/languages","stargazers_url":"https://api.github.com/repos/alexandrelaplante/django/stargazers","contributors_url":"https://api.github.com/repos/alexandrelaplante/django/contributors","subscribers_url":"https://api.github.com/repos/alexandrelaplante/django/subscribers","subscription_url":"https://api.github.com/repos/alexandrelaplante/django/subscription","commits_url":"https://api.github.com/repos/alexandrelaplante/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexandrelaplante/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexandrelaplante/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexandrelaplante/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexandrelaplante/django/contents/{+path}","compare_url":"https://api.github.com/repos/alexandrelaplante/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexandrelaplante/django/merges","archive_url":"https://api.github.com/repos/alexandrelaplante/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexandrelaplante/django/downloads","issues_url":"https://api.github.com/repos/alexandrelaplante/django/issues{/number}","pulls_url":"https://api.github.com/repos/alexandrelaplante/django/pulls{/number}","milestones_url":"https://api.github.com/repos/alexandrelaplante/django/milestones{/number}","notifications_url":"https://api.github.com/repos/alexandrelaplante/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexandrelaplante/django/labels{/name}","releases_url":"https://api.github.com/repos/alexandrelaplante/django/releases{/id}","deployments_url":"https://api.github.com/repos/alexandrelaplante/django/deployments","created_at":"2018-07-07T16:25:29Z","updated_at":"2018-07-07T16:25:48Z","pushed_at":"2018-07-08T02:44:06Z","git_url":"git://github.com/alexandrelaplante/django.git","ssh_url":"git@github.com:alexandrelaplante/django.git","clone_url":"https://github.com/alexandrelaplante/django.git","svn_url":"https://github.com/alexandrelaplante/django","homepage":"https://www.djangoproject.com/","size":177944,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"django:master","ref":"master","sha":"38e904e26576abffed3c257a1a741e1641c6f2de","user":{"login":"django","id":27804,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3ODA0","avatar_url":"https://avatars2.githubusercontent.com/u/27804?v=4","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"repo":{"id":4164482,"node_id":"MDEwOlJlcG9zaXRvcnk0MTY0NDgy","name":"django","full_name":"django/django","owner":{"login":"django","id":27804,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3ODA0","avatar_url":"https://avatars2.githubusercontent.com/u/27804?v=4","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/django/django","description":"The Web framework for perfectionists with deadlines.","fork":false,"url":"https://api.github.com/repos/django/django","forks_url":"https://api.github.com/repos/django/django/forks","keys_url":"https://api.github.com/repos/django/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/django/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/django/django/teams","hooks_url":"https://api.github.com/repos/django/django/hooks","issue_events_url":"https://api.github.com/repos/django/django/issues/events{/number}","events_url":"https://api.github.com/repos/django/django/events","assignees_url":"https://api.github.com/repos/django/django/assignees{/user}","branches_url":"https://api.github.com/repos/django/django/branches{/branch}","tags_url":"https://api.github.com/repos/django/django/tags","blobs_url":"https://api.github.com/repos/django/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/django/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/django/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/django/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/django/django/statuses/{sha}","languages_url":"https://api.github.com/repos/django/django/languages","stargazers_url":"https://api.github.com/repos/django/django/stargazers","contributors_url":"https://api.github.com/repos/django/django/contributors","subscribers_url":"https://api.github.com/repos/django/django/subscribers","subscription_url":"https://api.github.com/repos/django/django/subscription","commits_url":"https://api.github.com/repos/django/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/django/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/django/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/django/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/django/django/contents/{+path}","compare_url":"https://api.github.com/repos/django/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/django/django/merges","archive_url":"https://api.github.com/repos/django/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/django/django/downloads","issues_url":"https://api.github.com/repos/django/django/issues{/number}","pulls_url":"https://api.github.com/repos/django/django/pulls{/number}","milestones_url":"https://api.github.com/repos/django/django/milestones{/number}","notifications_url":"https://api.github.com/repos/django/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/django/django/labels{/name}","releases_url":"https://api.github.com/repos/django/django/releases{/id}","deployments_url":"https://api.github.com/repos/django/django/deployments","created_at":"2012-04-28T02:47:18Z","updated_at":"2018-07-08T01:10:27Z","pushed_at":"2018-07-08T02:45:05Z","git_url":"git://github.com/django/django.git","ssh_url":"git@github.com:django/django.git","clone_url":"https://github.com/django/django.git","svn_url":"https://github.com/django/django","homepage":"https://www.djangoproject.com/","size":177952,"stargazers_count":34960,"watchers_count":34960,"language":"Python","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14860,"mirror_url":null,"archived":false,"open_issues_count":179,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":14860,"open_issues":179,"watchers":34960,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/10146"},"html":{"href":"https://github.com/django/django/pull/10146"},"issue":{"href":"https://api.github.com/repos/django/django/issues/10146"},"comments":{"href":"https://api.github.com/repos/django/django/issues/10146/comments"},"review_comments":{"href":"https://api.github.com/repos/django/django/pulls/10146/comments"},"review_comment":{"href":"https://api.github.com/repos/django/django/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/django/django/pulls/10146/commits"},"statuses":{"href":"https://api.github.com/repos/django/django/statuses/093df8f0ac206fec6efd01d13c12fe7035899e51"}},"author_association":"NONE"}}
{"actor":{"display_login":"alexandrelaplante"}}