fix prefetch_related about existing objects

This commit is contained in:
Laura Klünder 2017-06-17 22:50:56 +02:00
parent 2cb66cbd64
commit 44811460a1

View file

@ -520,7 +520,12 @@ class BaseQueryWrapper(BaseWrapper):
obj._prefetch_done = True
obj._fetch_all()
result = [self._wrap_instance(instance) for instance in obj._result_cache] + list(self._get_created_objects())
result = [self._wrap_instance(instance) for instance in obj._result_cache]
obj._result_cache = result
obj._prefetch_done = False
obj._fetch_all()
result += list(self._get_created_objects())
for extra in self._extra:
ex = extra[22:]
@ -553,8 +558,6 @@ class BaseQueryWrapper(BaseWrapper):
raise NotImplementedError('Cannot do extra() for '+extra)
obj._result_cache = result
obj._prefetch_done = False
obj._fetch_all()
return result
@cached_property