diff --git a/docs/index.rst b/docs/index.rst index 9db0784..8285b64 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -73,6 +73,9 @@ documentation), the following configuration settings are available: ``SESSION_SET_TTL`` Whether or not to set the time-to-live of the session on the backend, if supported. Default is ``True``. +``SESSION_PICKLE_PROTOCOL`` The Pickling protocol to be used when storing + the session on the backend. Default is set to + the pickle module DEFAULT_PROTOCOL. ============================== ================================================ diff --git a/flask_kvsession/__init__.py b/flask_kvsession/__init__.py index bf0ee7e..f1d21a5 100644 --- a/flask_kvsession/__init__.py +++ b/flask_kvsession/__init__.py @@ -177,7 +177,12 @@ def save_session(self, app, session, response): app.config['SESSION_KEY_BITS'])).serialize() # save the session, now its no longer new (or modified) - data = self.serialization_method.dumps(dict(session)) + if 'SESSION_PICKLE_PROTOCOL' in current_app.config: + # A Pickle Protocol was specified in the Flask app configuration so we will attempt to respect it. + data = self.serialization_method.dumps(dict(session), + protocol=current_app.config['SESSION_PICKLE_PROTOCOL']) + else: + data = self.serialization_method.dumps(dict(session)) store = current_app.kvsession_store if getattr(store, 'ttl_support', False):