diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index d034261e64..c93ce80300 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -109,6 +109,15 @@ class QuerySetSetOperationTests(TestCase): qs2 = Number.objects.filter(num__gte=2, num__lte=3) self.assertNumbersEqual(qs1.union(qs2).order_by('-num'), [3, 2, 1, 0]) + def test_ordering_by_alias(self): + qs1 = Number.objects.filter(num__lte=1).values(alias=F('num')) + qs2 = Number.objects.filter(num__gte=2, num__lte=3).values(alias=F('num')) + self.assertQuerysetEqual( + qs1.union(qs2).order_by('-alias'), + [3, 2, 1, 0], + operator.itemgetter('alias'), + ) + def test_ordering_by_f_expression(self): qs1 = Number.objects.filter(num__lte=1) qs2 = Number.objects.filter(num__gte=2, num__lte=3) @@ -242,6 +251,8 @@ class QuerySetSetOperationTests(TestCase): # 'num' got realiased to num2 with self.assertRaisesMessage(DatabaseError, msg): list(qs1.union(qs2).order_by('num')) + with self.assertRaisesMessage(DatabaseError, msg): + list(qs1.union(qs2).order_by(F('num'))) # switched order, now 'exists' again: list(qs2.union(qs1).order_by('num'))