Don't cache default callable return value of None in cache.get_or_set()
In 82be474 the change was made to allow None as a default value passed to
BaseCache.get_or_set. In case the default value of None is used, it is not
stored in the cache. This still left open the possibility that default could
be a callable that returns None, in which case it would be stored in the
cache.
# This scenario works as expected.
cache.get_or_set('foo', None) # None
cache.get_or_set('foo', 5) # 5
cache.get('foo') # 5
# This scenario seems wrong.
cache.get_or_set('bar', lambda: None) # None
cache.get_or_set('bar', 5) # None :(
cache.get('bar') # None :(
Change History
(8)
Triage Stage: |
Unreviewed → Accepted
|
Version: |
1.11 → master
|
Description: |
modified (diff)
|
Summary: |
do not cache default callable return value of None in get_or_set → Don't cache default callable return value of None in cache.get_or_set()
|
Triage Stage: |
Accepted → Ready for checkin
|
Version: |
master → 1.11
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
I have already created a pull request for this issue, but I'm not sure how to officially associate it with this ticket so I'll just link to it here in a comment:
https://github.com/django/django/pull/9087