Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16378. Locmem now uses pickle.HIGHEST_PROTOCOL for better comp…

…atibility with other hash backends. Thanks aaugustin for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17136 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0506facd86082f48cc3cc3d3ea253e4ebbcd0ebe 1 parent 4d975b4
@PaulMcMillan PaulMcMillan authored
View
3  django/core/cache/backends/db.py
@@ -102,7 +102,8 @@ def _base_set(self, mode, key, value, timeout=None):
exp = exp.replace(microsecond=0)
if num > self._max_entries:
self._cull(db, cursor, now)
- encoded = base64.encodestring(pickle.dumps(value, 2)).strip()
+ pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
+ encoded = base64.encodestring(pickled).strip()
cursor.execute("SELECT cache_key, expires FROM %s "
"WHERE cache_key = %%s" % table, [key])
try:
View
9 django/core/cache/backends/locmem.py
@@ -31,7 +31,8 @@ def add(self, key, value, timeout=None, version=None):
exp = self._expire_info.get(key)
if exp is None or exp <= time.time():
try:
- self._set(key, pickle.dumps(value), timeout)
+ pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
+ self._set(key, pickled, timeout)
return True
except pickle.PickleError:
pass
@@ -49,7 +50,8 @@ def get(self, key, default=None, version=None):
return default
elif exp > time.time():
try:
- return pickle.loads(self._cache[key])
+ pickled = self._cache[key]
+ return pickle.loads(pickled)
except pickle.PickleError:
return default
finally:
@@ -78,7 +80,8 @@ def set(self, key, value, timeout=None, version=None):
self.validate_key(key)
self._lock.writer_enters()
try:
- self._set(key, pickle.dumps(value), timeout)
+ pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
+ self._set(key, pickled, timeout)
except pickle.PickleError:
pass
finally:
View
4 docs/releases/1.4.txt
@@ -501,6 +501,10 @@ Django 1.4 also includes several smaller improvements worth noting:
* Changed the default value for ``httponly`` on session cookies to
``True`` to help reduce the impact of potential XSS attacks.
+* Changed the ``locmem`` cache backend to use
+ ``pickle.HIGHEST_PROTOCOL`` for better compatibility with the other
+ cache backends.
+
.. _backwards-incompatible-changes-1.4:
Backwards incompatible changes in 1.4
Please sign in to comment.
Something went wrong with that request. Please try again.