

def test_queryset_or_only_one_with_precache(self):
    tournament_1 = self.t1
    tournament_2 = self.t2
    with self.assertNumQueries(2):
        pools = (tournament_1.pool_set.all() | Pool.objects.filter(pk=self.p3.pk))
        related_objects = set((pool.tournament for pool in pools))
        self.assertEqual(related_objects, {tournament_1, tournament_2})
    with self.assertNumQueries(2):
        pools = (Pool.objects.filter(pk=self.p3.pk) | tournament_1.pool_set.all())
        related_objects = set((pool.tournament for pool in pools))
        self.assertEqual(related_objects, {tournament_1, tournament_2})

dataset/ETHPy150Open django/django/tests/known_related_objects/tests.py ExistingRelatedInstancesTests.test_queryset_or_only_one_with_precache/original