1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

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

Backport of 4d60261b2a from master
This commit is contained in:
Daniel Tao
2017-09-15 16:16:44 -05:00
committed by Tim Graham
parent 9b8e76f96d
commit 45b0ec87d3
3 changed files with 14 additions and 6 deletions

View File

@@ -931,6 +931,11 @@ class BaseCacheTests(object):
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'"