async def test_subquery_access(self):
    'This test ensures that accessing a query does not modify it (#780)'
    tournament_1 = (await Tournament.create(name='1'))
    event_1 = (await Event.create(event_id=1, name='event 1', tournament=tournament_1))
    event_2 = (await Event.create(event_id=2, name='event 2', tournament=tournament_1))
    team_1 = (await Team.create(id=1, name='team 1'))
    team_2 = (await Team.create(id=2, name='team 2'))
    (await event_1.participants.add(team_1))
    (await event_2.participants.add(team_1, team_2))
    self.assertEqual((await event_1.participants.all()), [team_1])
    self.assertEqual((await event_2.participants.all()), [team_1, team_2])
    sub_query_team_1 = Subquery(Event.filter(participants__id=1).values('event_id'))
    sub_query_team_2 = Subquery(Event.filter(participants__id=2).values('event_id'))
    query = Event.filter(pk__in=sub_query_team_1)
    query = query.filter(pk__in=sub_query_team_2)
    self.assertEqual(query.sql(), query.sql())
    self.assertEqual((await query.count()), (await query.count()))
    self.assertEqual((await query.count()), 1)
    self.assertEqual((await query.all()), [event_2])
This test ensures that accessing a query does not modify it (#780)
async def test_subquery_access(self):
    
    tournament_1 = (await Tournament.create(name='1'))
    event_1 = (await Event.create(event_id=1, name='event 1', tournament=tournament_1))
    event_2 = (await Event.create(event_id=2, name='event 2', tournament=tournament_1))
    team_1 = (await Team.create(id=1, name='team 1'))
    team_2 = (await Team.create(id=2, name='team 2'))
    (await event_1.participants.add(team_1))
    (await event_2.participants.add(team_1, team_2))
    self.assertEqual((await event_1.participants.all()), [team_1])
    self.assertEqual((await event_2.participants.all()), [team_1, team_2])
    sub_query_team_1 = Subquery(Event.filter(participants__id=1).values('event_id'))
    sub_query_team_2 = Subquery(Event.filter(participants__id=2).values('event_id'))
    query = Event.filter(pk__in=sub_query_team_1)
    query = query.filter(pk__in=sub_query_team_2)
    self.assertEqual(query.sql(), query.sql())
    self.assertEqual((await query.count()), (await query.count()))
    self.assertEqual((await query.count()), 1)
    self.assertEqual((await query.all()), [event_2])