Refs #30727 -- Added tests for Subquery with queryset in kwargs pickle without evaluating it.

This commit is contained in:
Mariusz Felisiak 2020-05-19 21:05:52 +02:00
parent 5af17babb0
commit b739f2e91d
1 changed files with 12 additions and 0 deletions

View File

@ -195,6 +195,18 @@ class PickleabilityTestCase(TestCase):
with self.assertNumQueries(0):
self.assert_pickles(groups)
def test_pickle_exists_kwargs_queryset_not_evaluated(self):
group = Group.objects.create(name='group')
Event.objects.create(title='event', group=group)
groups = Group.objects.annotate(
has_event=models.Exists(
queryset=Event.objects.filter(group_id=models.OuterRef('id')),
),
)
list(groups) # evaluate QuerySet.
with self.assertNumQueries(0):
self.assert_pickles(groups)
def test_pickle_subquery_queryset_not_evaluated(self):
group = Group.objects.create(name='group')
Event.objects.create(title='event', group=group)