Make repr of NoValue output a consistent value

Declined
#61 · Created  · Last updated

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: ·2017-06-23

Description

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.

0 attachments

0 comments

Loading commits...