diff options
author | Sean Reifschneider <sean@realgo.com> | 2014-09-24 15:59:42 -0600 |
---|---|---|
committer | Sean Reifschneider <sean@realgo.com> | 2014-09-24 15:59:42 -0600 |
commit | a4baa533d884a3067ecb28d3a2fc81f0f4d5b913 (patch) | |
tree | 5208c978b97fdaaa54419c855929e891cecef8bf | |
parent | 0864fa4c50aeab49e1adb4551730fa0dacff4889 (diff) | |
download | python-memcached-a4baa533d884a3067ecb28d3a2fc81f0f4d5b913.tar.gz |
Fixes for empty/None keys.
Empty keys with a prefix are ok (for _multi() mostly).
_multi() was silently converting None key to a string.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | memcache.py | 13 |
2 files changed, 14 insertions, 1 deletions
@@ -1,3 +1,5 @@ + * Allowing empty key in _multi() calls. Suggested by sergio97 on github. + Sun, 21 Sep 2014 13:41:30 -0600 Sean Reifschneider <jafo@tummy.com> * 1.54 release. diff --git a/memcache.py b/memcache.py index 074a340..fc548b0 100644 --- a/memcache.py +++ b/memcache.py @@ -715,11 +715,16 @@ class Client(threading.local): # server. Returns the mangled key. server, key = self._get_server( (orig_key[0], key_prefix + str_orig_key)) + orig_key = orig_key[1] else: # set_multi supports int / long keys. str_orig_key = str(orig_key) server, key = self._get_server(key_prefix + str_orig_key) + # alert when passed in key is None + if orig_key is None: + self.check_key(orig_key, key_extra_len=key_extra_len) + # Now check to make sure key length is proper ... if self.do_check_key: self.check_key(str_orig_key, key_extra_len=key_extra_len) @@ -1173,8 +1178,14 @@ class Client(threading.local): """ if isinstance(key, tuple): key = key[1] - if not key: + if key is None: raise Client.MemcachedKeyNoneError("Key is None") + if key is '': + if key_extra_len is 0: + raise Client.MemcachedKeyNoneError("Key is empty") + + # key is empty but there is some other component to key + return # Make sure we're not a specific unicode type, if we're old enough that # it's a separate type. |