diff options
| author | Daniel Tao <daniel.tao@gmail.com> | 2017-09-15 16:16:44 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-10-10 09:20:34 -0400 |
| commit | 4d60261b2a77460b4c127c3d832518b95e11a0ac (patch) | |
| tree | 0d2baa5dd9ea66f71b26d6a58e68ffc8e0e424b4 /django | |
| parent | 0e212a705e6b2e49a246b16286036c40ec2ac4f8 (diff) | |
Fixed #28601 -- Prevented cache.get_or_set() from caching None if default is a callable that returns None.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/cache/backends/base.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index aaf34c042e..cf0df7cc68 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -155,13 +155,15 @@ class BaseCache: 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): |
