Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #29867 -- Added support for storing None value in caches. #13671

Merged
merged 2 commits into from Dec 17, 2020

Conversation

ngnpope
Copy link
Member

@ngnpope ngnpope commented Nov 12, 2020

Fixes ticket-29867, supersedes #11812 and #13055
This is following on from my comments in #11812 in particular.

Many of the cache operations make use of get() with the implicit default=None and assume that the returned None value indicates the value is not stored. This may not be true as None can be explicitly set into the cache. The fix is to use a sentinel object as the default in the absence of the key in the cache.

Unfortunately this does not work for python-memcached, so we introduce a feature flag to keep the existing behaviour for that backend.

@ngnpope ngnpope changed the title [PoC] Support None values stored in caches. Fixed #29867 -- Added support for stored None value in caches. Dec 14, 2020
@ngnpope ngnpope requested a review from felixxm December 14, 2020 12:09
@ngnpope ngnpope marked this pull request as ready for review December 14, 2020 12:09
@felixxm felixxm self-assigned this Dec 15, 2020
Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pope1ni Thanks 👍 This looks great 🚀

django/core/cache/backends/base.py Outdated Show resolved Hide resolved
tests/cache/tests.py Outdated Show resolved Hide resolved
django/core/cache/backends/base.py Outdated Show resolved Hide resolved
docs/topics/cache.txt Show resolved Hide resolved
@ngnpope
Copy link
Member Author

ngnpope commented Dec 16, 2020

Thanks for the review. Updated.

docs/releases/3.2.txt Outdated Show resolved Hide resolved
Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pope1ni Thanks 👍 I pushed minor edits to tests and backends. I'm going to check docs tomorrow.

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed small edits to docs.

docs/topics/cache.txt Outdated Show resolved Hide resolved
Many of the cache operations make use of the default argument to the
.get() operation to determine whether the key was found in the cache.
The default value of the default argument is None, so this results in
these operations assuming that None is not stored in the cache when it
actually is. Adding a sentinel object solves this issue.

Unfortunately the unmaintained python-memcached library does not support
a default argument to .get(), so the previous behavior is preserved for
the deprecated MemcachedCache backend.
@felixxm felixxm changed the title Fixed #29867 -- Added support for stored None value in caches. Fixed #29867 -- Added support for storing None value in caches. Dec 17, 2020
@felixxm felixxm merged commit bb64b99 into django:master Dec 17, 2020
@ngnpope ngnpope deleted the cache-stored-none branch December 17, 2020 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants