summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDaniel Tao <daniel.tao@gmail.com>2017-09-15 16:16:44 -0500
committerTim Graham <timograham@gmail.com>2017-10-10 09:35:57 -0400
commit45b0ec87d3d7c60c60b0f1c69cd89789bafaa6a8 (patch)
tree2e311403883cce2a9a4273e633afea911788b96c /django
parent9b8e76f96dcb755a2cbf4846888058eae2510cf8 (diff)
[1.11.x] Fixed #28601 -- Prevented cache.get_or_set() from caching None if default is a callable that returns None.
Backport of 4d60261b2a77460b4c127c3d832518b95e11a0ac from master
Diffstat (limited to 'django')
-rw-r--r--django/core/cache/backends/base.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index 9cbfe0be1d..1235f7e098 100644
--- a/django/core/cache/backends/base.py
+++ b/django/core/cache/backends/base.py
@@ -157,13 +157,15 @@ class BaseCache(object):
Return the value of the key stored or retrieved.
"""
val = self.get(key, version=version)
- if val is None and default is not None:
+ if val is None:
if callable(default):
default = default()
- self.add(key, default, timeout=timeout, version=version)
- # Fetch the value again to avoid a race condition if another caller
- # added a value between the first get() and the add() above.
- return self.get(key, default, version=version)
+ if default is not None:
+ self.add(key, default, timeout=timeout, version=version)
+ # Fetch the value again to avoid a race condition if another
+ # caller added a value between the first get() and the add()
+ # above.
+ return self.get(key, default, version=version)
return val
def has_key(self, key, version=None):