unicode strings cause error on dbm backend - python 2.7 & bsddb

Issue #6 wontfix
jvanasco
created an issue

i kept getting this error:

{{{ File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/cache/region.py", line 385, in decorate return self.get_or_create(key, creator, expiration_time) File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/cache/region.py", line 255, in get_or_create value_and_created_fn=get_value) as value: File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/core/dogpile.py", line 83, in enter value_and_created_fn) File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/core/dogpile.py", line 114, in _enter value = value_fn() File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/cache/region.py", line 242, in get_value value = self.backend.get(key) File "/Users/jvanasco/webserver/environments/newproject-2.7/lib/python2.7/site-packages/dogpile/cache/backends/file.py", line 166, in get value = dbm.get(key, NO_VALUE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_abcoll.py", line 336, in get return self[key] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bsddb/init.py", line 270, in getitem return _DeadlockWrap(lambda: self.db[key]) # self.db[key] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap return function(_args, *_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bsddb/init.py", line 270, in <lambda> return _DeadlockWrap(lambda: self.db[key]) # self.db[key] }}}

it seems that bsddb doesn't like the unicode strings that are default in pyramid and other apps.

the quick fix is to convert the key to a string

I'm not sure if this is specific to bsddb or will be an issue with other backends ( memcached, etc), but a simple global fix is to add a conversion to dogpile/cache/region.py

{{{

    if self.key_mangler:
        key = self.key_mangler(key)

+ + key = str(key) + def get_value(): value = self.backend.get(key)

}}}

Comments (4)

  1. Log in to comment