# HG changeset patch # User Laurent Peuch # Date 1557343844 -7200 # Node ID 85f82900f1c32f4735a1f97c5b87cf65d847a16c # Parent fa292e905edc2387da88bdb87e89c3e42e035550 DeprecationWarning: The default pickle serializer is deprecated as of Pyramid 1.9 and it will be changed to use pyramid.session.JSONSerializer in version 2.0. Explicitly set the serializer to avoid future incompatibilities . See "Upcoming Changes to ISession in Pyramid 2.0" for more information about this change. As describe here https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/sessions.html#pickle-session-deprecation use a serializer that fallback on pickle if needed to avoid impacting users. diff -r fa292e905edc -r 85f82900f1c3 cubicweb/pyramid/session.py --- a/cubicweb/pyramid/session.py Wed May 08 20:53:49 2019 +0200 +++ b/cubicweb/pyramid/session.py Wed May 08 21:30:44 2019 +0200 @@ -89,7 +89,7 @@ from contextlib import contextmanager from pyramid.compat import pickle -from pyramid.session import SignedCookieSessionFactory +from pyramid.session import SignedCookieSessionFactory, JSONSerializer, PickleSerializer from cubicweb import ( Binary, @@ -129,6 +129,24 @@ yield cnx +class JSONSerializerWithPickleFallback(object): + def __init__(self): + self.json = JSONSerializer() + self.pickle = PickleSerializer() + + def dumps(self, value): + # maybe catch serialization errors here and keep using pickle + # while finding spots in your app that are not storing + # JSON-serializable objects, falling back to pickle + return self.json.dumps(value) + + def loads(self, value): + try: + return self.json.loads(value) + except ValueError: + return self.pickle.loads(value) + + def CWSessionFactory( secret, cookie_name='session', @@ -177,7 +195,7 @@ reissue_time=reissue_time, hashalg=hashalg, salt=salt, - serializer=serializer) + serializer=serializer if serializer else JSONSerializerWithPickleFallback()) class CWSession(SignedCookieSession): def __init__(self, request):