Ticket #35437: test_ordering_in_distinct_exists_subquery.2.diff

File test_ordering_in_distinct_exists_subquery.2.diff, 1.5 KB (added by Kevin Marsh, 6 months ago)

Failing test

  • tests/expressions/tests.py

    diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
    index f7233305a7..0d7e05eb0a 100644
    a b def test_subquery(self):  
    685685            Employee.objects.exclude(company_point_of_contact_set=None).values("pk"),
    686686        )
    687687
     688    @skipUnlessDBFeature("can_distinct_on_fields")
     689    def test_ordering_in_distinct_exists_subquery(self):
     690        # Show that the inner Exists query
     691        # respects the ordering when it is distinct
     692        manager = Manager.objects.create(name="King Arthur")
     693        Employee.objects.create(
     694            manager=manager,
     695            salary=10,
     696            firstname="Robin",
     697            lastname="The Not-So-Brave",
     698        )
     699        lancelot = Employee.objects.create(
     700            manager=manager,
     701            salary=20,  # Higher than Robin's
     702            firstname="Lancelot",
     703            lastname="The Brave",
     704        )
     705
     706        highest_paid_per_manager_subquery = (
     707            Employee
     708            .objects
     709            .filter(manager__isnull=False)
     710            .order_by("manager", "-salary")
     711            .distinct("manager")
     712            .filter(pk=OuterRef("pk"))
     713        )
     714        qs = Employee.objects.filter(Exists(highest_paid_per_manager_subquery))
     715        self.assertEqual(qs.get(manager=manager), lancelot)
     716
     717
    688718    def test_subquery_eq(self):
    689719        qs = Employee.objects.annotate(
    690720            is_ceo=Exists(Company.objects.filter(ceo=OuterRef("pk"))),
Back to Top