Resolve #367: Set pickle protocol version for the Redis backend (#369)

This commit is contained in:
Elisey Zanko 2020-01-15 01:46:27 +05:00 committed by Camilo Nova
parent 590fa02eb3
commit b62206da57
4 changed files with 17 additions and 1 deletions

View file

@ -41,3 +41,4 @@ vl <1844144@gmail.com>
vl <vl@u64.(none)>
Dmitriy Tatarkin <mail@dtatarkin.ru>
Alexandr Artemyev <mogost@gmail.com>
Elisey Zanko <elisey.zanko@gmail.com>

View file

@ -44,7 +44,7 @@ class RedisBackend(Backend):
def set(self, key, value):
old_value = self.get(key)
self._rd.set(self.add_prefix(key), dumps(value))
self._rd.set(self.add_prefix(key), dumps(value, protocol=settings.REDIS_PICKLE_VERSION))
signals.config_updated.send(
sender=config, key=key, old_value=old_value, new_value=value
)

View file

@ -1,3 +1,5 @@
import pickle
from django.conf import settings
BACKEND = getattr(
@ -36,6 +38,8 @@ REDIS_CONNECTION_CLASS = getattr(
REDIS_CONNECTION = getattr(settings, 'CONSTANCE_REDIS_CONNECTION', {})
REDIS_PICKLE_VERSION = getattr(settings, 'CONSTANCE_REDIS_PICKLE_VERSION', pickle.DEFAULT_PROTOCOL)
SUPERUSER_ONLY = getattr(settings, 'CONSTANCE_SUPERUSER_ONLY', True)
IGNORE_ADMIN_VERSION_CHECK = getattr(

View file

@ -66,6 +66,17 @@ database. Defaults to ``'constance:'``. E.g.::
CONSTANCE_REDIS_PREFIX = 'constance:myproject:'
``CONSTANCE_REDIS_PICKLE_VERSION``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The (optional) protocol version of pickle you want to use to serialize your python
objects when storing in the Redis database. Defaults to ``pickle.DEFAULT_PROTOCOL``. E.g.::
CONSTANCE_REDIS_PICKLE_VERSION = pickle.DEFAULT_PROTOCOL
You might want to pin this value to a specific protocol number, since ``pickle.DEFAULT_PROTOCOL``
means different things between versions of Python.
Database
--------