Skip to content

Commit

Permalink
Fix querysets with custom .iterator()
Browse files Browse the repository at this point in the history
Closes #222.
  • Loading branch information
Suor committed Dec 13, 2016
1 parent 883cc94 commit c5fb0dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cacheops/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,17 @@ def _fetch_all(self):
lock = self._cacheprofile['lock']

if self._cacheprofile['write_only'] or self._for_write:
self._result_cache = list(self._no_monkey.iterator(self))
# TODO: remove .nocache() when iterator() is dropped
self._result_cache = list(self.nocache().iterator())
self._cache_results(cache_key, self._result_cache)
else:
with redis_client.getting(cache_key, lock=lock) as cache_data:
cache_read.send(sender=self.model, func=None, hit=cache_data is not None)
if cache_data is not None:
self._result_cache = pickle.loads(cache_data)
else:
self._result_cache = list(self._no_monkey.iterator(self))
# TODO: remove .nocache() when iterator() is dropped
self._result_cache = list(self.nocache().iterator())
self._cache_results(cache_key, self._result_cache)

self._no_monkey._fetch_all(self)
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,12 @@ def _target():
self.assertEquals(results[0], results[1])


# TODO: remove this test when .iterator() is dropped
class PolymorphicTests(BaseTestCase):
def test_polymorphic(self):
b = PolymorphicB.objects.create()
z = PolymorphicZ.objects.create(a=b)
z2 = PolymorphicZ.objects.get(id=z.id)
self.assertEqual(type(z.a), PolymorphicB)
self.assertEqual(type(z2.a), PolymorphicB)


Expand Down

0 comments on commit c5fb0dc

Please sign in to comment.