| 57 | a.first().b.first().c.first().d.first() |
| 58 | |
| 59 | |
| 60 | class PrefetchManyTest(TestCase): |
| 61 | def setUp(self): |
| 62 | e = E.objects.create() |
| 63 | f = F.objects.create() |
| 64 | g = G.objects.create() |
| 65 | h = H.objects.create() |
| 66 | f.e.add(e) |
| 67 | g.f.add(f) |
| 68 | h.g.add(g) |
| 69 | |
| 70 | def test_with_prefetch(self): |
| 71 | g = G.objects.prefetch_related(Prefetch('h')) |
| 72 | f = F.objects.prefetch_related(Prefetch('g', queryset=g)) |
| 73 | e = E.objects.prefetch_related(Prefetch('f', queryset=f)) |
| 74 | list(e) |
| 75 | e.first().f.first().g.first().h.first() |
| 76 | |
| 77 | def test_without_prefetch(self): |
| 78 | g = G.objects.prefetch_related('h') |
| 79 | f = F.objects.prefetch_related(Prefetch('g', queryset=g)) |
| 80 | e = E.objects.prefetch_related(Prefetch('f', queryset=f)) |
| 81 | list(e) |
| 82 | e.first().f.first().g.first().h.first() |
49 | | File "/home/gagaro/django/modules/test/django_test/models_test/tests.py", line 19, in test_with_prefetch |
| 92 | File "/home/gagaro/django/modules/test/django_test/models_test/tests.py", line 49, in test_with_prefetch |
| 93 | e.first().f.first().g.first().h.first() |
| 94 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 543, in first |
| 95 | objects = list((self if self.ordered else self.order_by('pk'))[:1]) |
| 96 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__ |
| 97 | self._fetch_all() |
| 98 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1065, in _fetch_all |
| 99 | self._prefetch_related_objects() |
| 100 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 649, in _prefetch_related_objects |
| 101 | prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) |
| 102 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1426, in prefetch_related_objects |
| 103 | (through_attr, first_obj.__class__.__name__, lookup.prefetch_through)) |
| 104 | AttributeError: Cannot find 'f' on F object, 'f__f__g' is an invalid parameter to prefetch_related() |
| 105 | |
| 106 | ====================================================================== |
| 107 | ERROR: test_without_prefetch (models_test.tests.PrefetchManyTest) |
| 108 | ---------------------------------------------------------------------- |
| 109 | Traceback (most recent call last): |
| 110 | File "/home/gagaro/django/modules/test/django_test/models_test/tests.py", line 56, in test_without_prefetch |
| 111 | e.first().f.first().g.first().h.first() |
| 112 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 543, in first |
| 113 | objects = list((self if self.ordered else self.order_by('pk'))[:1]) |
| 114 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__ |
| 115 | self._fetch_all() |
| 116 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1065, in _fetch_all |
| 117 | self._prefetch_related_objects() |
| 118 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 649, in _prefetch_related_objects |
| 119 | prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) |
| 120 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1426, in prefetch_related_objects |
| 121 | (through_attr, first_obj.__class__.__name__, lookup.prefetch_through)) |
| 122 | AttributeError: Cannot find 'f' on F object, 'f__f__g' is an invalid parameter to prefetch_related() |
| 123 | |
| 124 | ====================================================================== |
| 125 | ERROR: test_with_prefetch (models_test.tests.PrefetchForeignKeyTest) |
| 126 | ---------------------------------------------------------------------- |
| 127 | Traceback (most recent call last): |
| 128 | File "/home/gagaro/django/modules/test/django_test/models_test/tests.py", line 23, in test_with_prefetch |
| 151 | |
| 152 | ====================================================================== |
| 153 | ERROR: test_without_prefetch (models_test.tests.PrefetchForeignKeyTest) |
| 154 | ---------------------------------------------------------------------- |
| 155 | Traceback (most recent call last): |
| 156 | File "/home/gagaro/django/modules/test/django_test/models_test/tests.py", line 31, in test_without_prefetch |
| 157 | a.first().b.first().c.first().d.first() |
| 158 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 543, in first |
| 159 | objects = list((self if self.ordered else self.order_by('pk'))[:1]) |
| 160 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__ |
| 161 | self._fetch_all() |
| 162 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1065, in _fetch_all |
| 163 | self._prefetch_related_objects() |
| 164 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 649, in _prefetch_related_objects |
| 165 | prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) |
| 166 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1437, in prefetch_related_objects |
| 167 | obj_list, additional_lookups = prefetch_one_level(obj_list, prefetcher, lookup, level) |
| 168 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1536, in prefetch_one_level |
| 169 | prefetcher.get_prefetch_queryset(instances, lookup.get_current_queryset(level))) |
| 170 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 753, in get_prefetch_queryset |
| 171 | for rel_obj in queryset: |
| 172 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__ |
| 173 | self._fetch_all() |
| 174 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1065, in _fetch_all |
| 175 | self._prefetch_related_objects() |
| 176 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 649, in _prefetch_related_objects |
| 177 | prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) |
| 178 | File "/home/gagaro/.virtualenvs/django-test/local/lib/python2.7/site-packages/django/db/models/query.py", line 1426, in prefetch_related_objects |
| 179 | (through_attr, first_obj.__class__.__name__, lookup.prefetch_through)) |
| 180 | AttributeError: Cannot find 'b' on B object, 'b__c' is an invalid parameter to prefetch_related() |