Make repr of NoValue output a consistent value
Paul Brown
Branch: pawl/dogpile.cache:add_no_value_repr
Branch: zzzeek/dogpile.cache:master
Declined
Declined pull request
Dear contributor - This pull request is being moved to Gerrit, at https://gerrit.sqlalchemy.org/439, where it may be tested and reviewed more closely. As such, the pull request itself is being marked "closed" or "declined", however your contribution is merely being moved to our central review system. Please register at https://gerrit.sqlalchemy.org#/register/ to send and receive comments regarding this item.
Closed by: Mike Bayer·2017-06-23
I was creating a cache key based off of another cache key like this:
last_updated = cache_region.get('last_updated') cache_key = 'posts_{}'.format(last_updated) cache_region.get(cache_key)
In that case,
cache_key
ends up being something like: `posts_<dogpile.cache.api.NoValue object at 0x10360cc10>
That caused an unexpected bug where each web worker had a different memory location for NoValue and the web application was getting/setting to different cache keys for effectively the same thing.
I ended up fixing it like this:
from dogpile.cache.api import NO_VALUE last_updated = cache_region.get('last_updated') if last_updated is NO_VALUE: last_updated = None
However, I think we could prevent some potential bugs if we set the
__repr__
of NoValue to something consistent like this PR does.