Opened 5 years ago

Last modified 5 years ago

#28601 closed Cleanup/optimization

do not cache default callable return value of None in get_or_set — at Version 4

Reported by: Dan Tao Owned by: nobody
Component: Core (Cache system) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Dan Tao)

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 (4)

comment:1 Changed 5 years ago by Dan Tao

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

comment:2 Changed 5 years ago by Sergey Fedoseev

Has patch: set

comment:3 Changed 5 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted
Version: 1.11master

comment:4 Changed 5 years ago by Dan Tao

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top