summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Reifschneider <sean@realgo.com>2014-09-24 15:59:42 -0600
committerSean Reifschneider <sean@realgo.com>2014-09-24 15:59:42 -0600
commita4baa533d884a3067ecb28d3a2fc81f0f4d5b913 (patch)
tree5208c978b97fdaaa54419c855929e891cecef8bf
parent0864fa4c50aeab49e1adb4551730fa0dacff4889 (diff)
downloadpython-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--ChangeLog2
-rw-r--r--memcache.py13
2 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c44367..c15bf2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.