-
Notifications
You must be signed in to change notification settings - Fork 111
/
test_prefetch.py
35 lines (29 loc) · 969 Bytes
/
test_prefetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.db.models import Prefetch
from django.test import TestCase
from tests.models import A, B, C, D
class TestPrefetch(TestCase):
"""Tests prefetch corner-case bugs introduced in Django 1.7
See dynamic_rest.patches for details.
"""
def test_nested_prefetch(self):
a = A.objects.create(name="a")
b = B.objects.create(a=a)
d = D.objects.create(name="d")
C.objects.create(b=b, d=d)
# This fails
A.objects.prefetch_related(
Prefetch(
'b',
queryset=B.objects.prefetch_related(
Prefetch(
'cs',
queryset=C.objects.prefetch_related(
Prefetch(
'd',
queryset=D.objects.all()
)
)
)
)
)
)[0]