diff options
author | Simon Charette <charette.s@gmail.com> | 2022-07-04 21:51:07 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-10-05 14:04:49 +0200 |
commit | c58a8acd413ccc992dd30afd98ed900897e1f719 (patch) | |
tree | de41656a5439b66da60bf1d6470887a0e7dea33a /tests/queries | |
parent | 344d31c7e9ede4088e85c859f488d7a926918ec0 (diff) | |
download | django-c58a8acd413ccc992dd30afd98ed900897e1f719.tar.gz |
Fixed #33768 -- Fixed ordering compound queries by nulls_first/nulls_last on MySQL.
Columns of the left outer most select statement in a combined query
can be referenced by alias just like by index.
This removes combined query ordering by column index and avoids an
unnecessary usage of RawSQL which causes issues for backends that
specialize the treatment of null ordering.
Diffstat (limited to 'tests/queries')
-rw-r--r-- | tests/queries/test_qs_combinators.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index 3cd19d5f31..5fc09ca922 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -61,6 +61,24 @@ class QuerySetSetOperationTests(TestCase): self.assertSequenceEqual(qs3.none(), []) self.assertNumbersEqual(qs3, [0, 1, 8, 9], ordered=False) + def test_union_order_with_null_first_last(self): + Number.objects.filter(other_num=5).update(other_num=None) + qs1 = Number.objects.filter(num__lte=1) + qs2 = Number.objects.filter(num__gte=2) + qs3 = qs1.union(qs2) + self.assertSequenceEqual( + qs3.order_by( + F("other_num").asc(nulls_first=True), + ).values_list("other_num", flat=True), + [None, 1, 2, 3, 4, 6, 7, 8, 9, 10], + ) + self.assertSequenceEqual( + qs3.order_by( + F("other_num").asc(nulls_last=True), + ).values_list("other_num", flat=True), + [1, 2, 3, 4, 6, 7, 8, 9, 10, None], + ) + @skipUnlessDBFeature("supports_select_intersection") def test_intersection_with_empty_qs(self): qs1 = Number.objects.all() |