Fix cache_memoize to work with non-sequence data.
Review Request #11856 — Created Oct. 17, 2021 and submitted
The size checks in cache_memoize were causing it to fail when the
cached function was returning something other than a sequence. This
change fixes it so we only do those length checks for string types.While I was in here I fixed up a few small style issues.
- Used with a change that required this.
- Ran unit tests.
Summary | ID |
---|---|
dcfd5df252230cd99ee1995d573918812fb2f714 |
Description | From | Last Updated |
---|---|---|
E501 line too long (80 > 79 characters) |
reviewbot | |
We can't get rid of use_generator without a major version bump. Let's leave it in and put up a deprecation … |
chipx86 | |
Can you add a "Version Changed" here to notify that non-string/list types are now supported? |
chipx86 | |
This comment is old and wrong about some details, though the general problem remains. Maybe worth updating? Looking at the … |
chipx86 | |
While here, can you change this to unicode? |
chipx86 | |
Same here. |
chipx86 | |
Minor thing, but want to change these as well to be cache_func and cache_called? |
chipx86 |
- Commits:
-
Summary ID 77a67c2dcc611edaaa050d8fadb46897da43bb8d b75ff82c039eb432e3112eb20cd71fdb2ded5e99
Checks run (2 succeeded)
-
-
We can't get rid of
use_generator
without a major version bump. Let's leave it in and put up a deprecation notice in the docs and call, schedule it for removal in 3.0. -
-
This comment is old and wrong about some details, though the general problem remains. Maybe worth updating?
Looking at the code, it's not so much that python-memcached/pylibmc fails silently anymore, or even has an exception for this. It actually returns a result. We just don't know about it. Django, however, does, and clears out the key.
(Interestingly, pylibmc attempts to compress the data to make it fit, before deciding whether to give up.)
Original problem remains: We don't know, we can't find out through setting the data, and we still have to check. As the comment says, it's still not good enough. Pylibmc checks against encoded UTF-8 data, for strings, and Pickled data for anything not otherwise handled (non-ints/longs/strings).
Crappy situation. I really wish Django returned a result or something for us. It'd be easier to more effectively support other backends, too.
-
-
-