mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #34123 -- Fixed combinator order by alias when using select_related().
Regression in c58a8acd41.
Thanks to Shai Berger for the report and tests.
Co-Authored-By: David Sanders <shang.xiao.sanders@gmail.com>
This commit is contained in:
committed by
Mariusz Felisiak
parent
7adb0c8b60
commit
70499b25c7
@@ -304,6 +304,34 @@ class QuerySetSetOperationTests(TestCase):
|
||||
operator.itemgetter("num"),
|
||||
)
|
||||
|
||||
def test_union_with_select_related_and_order(self):
|
||||
e1 = ExtraInfo.objects.create(value=7, info="e1")
|
||||
a1 = Author.objects.create(name="a1", num=1, extra=e1)
|
||||
a2 = Author.objects.create(name="a2", num=3, extra=e1)
|
||||
Author.objects.create(name="a3", num=2, extra=e1)
|
||||
base_qs = Author.objects.select_related("extra").order_by()
|
||||
qs1 = base_qs.filter(name="a1")
|
||||
qs2 = base_qs.filter(name="a2")
|
||||
self.assertSequenceEqual(qs1.union(qs2).order_by("pk"), [a1, a2])
|
||||
|
||||
@skipUnlessDBFeature("supports_slicing_ordering_in_compound")
|
||||
def test_union_with_select_related_and_first(self):
|
||||
e1 = ExtraInfo.objects.create(value=7, info="e1")
|
||||
a1 = Author.objects.create(name="a1", num=1, extra=e1)
|
||||
Author.objects.create(name="a2", num=3, extra=e1)
|
||||
base_qs = Author.objects.select_related("extra")
|
||||
qs1 = base_qs.filter(name="a1")
|
||||
qs2 = base_qs.filter(name="a2")
|
||||
self.assertEqual(qs1.union(qs2).first(), a1)
|
||||
|
||||
def test_union_with_first(self):
|
||||
e1 = ExtraInfo.objects.create(value=7, info="e1")
|
||||
a1 = Author.objects.create(name="a1", num=1, extra=e1)
|
||||
base_qs = Author.objects.order_by()
|
||||
qs1 = base_qs.filter(name="a1")
|
||||
qs2 = base_qs.filter(name="a2")
|
||||
self.assertEqual(qs1.union(qs2).first(), a1)
|
||||
|
||||
def test_union_multiple_models_with_values_list_and_order(self):
|
||||
reserved_name = ReservedName.objects.create(name="rn1", order=0)
|
||||
qs1 = Celebrity.objects.all()
|
||||
|
||||
Reference in New Issue
Block a user