mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #20577 -- Deferred filtering of prefetched related querysets by reverse m2o relation.
This commit is contained in:
committed by
Mariusz Felisiak
parent
999cddd58d
commit
036f160733
@@ -294,17 +294,20 @@ class PrefetchRelatedTests(TestDataMixin, TestCase):
|
||||
|
||||
def test_filter_deferred(self):
|
||||
"""
|
||||
Related filtering of prefetched querysets is deferred until necessary.
|
||||
Related filtering of prefetched querysets is deferred on m2m and
|
||||
reverse m2o relations until necessary.
|
||||
"""
|
||||
add_q = Query.add_q
|
||||
with mock.patch.object(
|
||||
Query,
|
||||
'add_q',
|
||||
autospec=True,
|
||||
side_effect=lambda self, q: add_q(self, q),
|
||||
) as add_q_mock:
|
||||
list(Book.objects.prefetch_related('authors'))
|
||||
self.assertEqual(add_q_mock.call_count, 1)
|
||||
for relation in ['authors', 'first_time_authors']:
|
||||
with self.subTest(relation=relation):
|
||||
with mock.patch.object(
|
||||
Query,
|
||||
'add_q',
|
||||
autospec=True,
|
||||
side_effect=lambda self, q: add_q(self, q),
|
||||
) as add_q_mock:
|
||||
list(Book.objects.prefetch_related(relation))
|
||||
self.assertEqual(add_q_mock.call_count, 1)
|
||||
|
||||
|
||||
class RawQuerySetTests(TestDataMixin, TestCase):
|
||||
|
||||
Reference in New Issue
Block a user