1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #28601 -- Prevented cache.get_or_set() from caching None if default is a callable that returns None.

This commit is contained in:
Daniel Tao
2017-09-15 16:16:44 -05:00
committed by Tim Graham
parent 0e212a705e
commit 4d60261b2a
3 changed files with 14 additions and 6 deletions

View File

@@ -924,6 +924,11 @@ class BaseCacheTests:
self.assertEqual(cache.get_or_set('mykey', my_callable), 'value')
self.assertEqual(cache.get_or_set('mykey', my_callable()), 'value')
def test_get_or_set_callable_returning_none(self):
self.assertIsNone(cache.get_or_set('mykey', lambda: None))
# Previous get_or_set() doesn't store None in the cache.
self.assertEqual(cache.get('mykey', 'default'), 'default')
def test_get_or_set_version(self):
msg = "get_or_set() missing 1 required positional argument: 'default'"
cache.get_or_set('brian', 1979, version=2)