Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for (optionally) declaring the Pickle Protocol when writing to session store #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
============================== ================================================


Expand Down
7 changes: 6 additions & 1 deletion flask_kvsession/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down