Merge pull request #23037 from edx/feanil/bom-939

BOM-939 Update pickle procotol version.
This commit is contained in:
Feanil Patel
2020-02-10 11:36:20 -05:00
committed by GitHub
5 changed files with 10 additions and 17 deletions

View File

@@ -837,7 +837,7 @@ COURSES_WITH_UNSAFE_CODE = []
DEBUG = False
SESSION_COOKIE_SECURE = False
SESSION_SAVE_EVERY_REQUEST = False
SESSION_SERIALIZER = 'openedx.core.lib.session_serializers.PickleV2Serializer'
SESSION_SERIALIZER = 'openedx.core.lib.session_serializers.PickleSerializer'
SESSION_COOKIE_DOMAIN = ""
SESSION_COOKIE_NAME = 'sessionid'

View File

@@ -256,7 +256,7 @@ class CourseStructureCache(object):
return None
with TIMER.timer("CourseStructureCache.set", course_context) as tagger:
pickled_data = pickle.dumps(structure, 2) # Protocol can't be incremented until cache is cleared
pickled_data = pickle.dumps(structure, 4) # Protocol can't be incremented until cache is cleared
tagger.measure('uncompressed_size', len(pickled_data))
# 1 = Fastest (slightly larger results)

View File

@@ -1105,7 +1105,7 @@ DEBUG = False
USE_TZ = True
SESSION_COOKIE_SECURE = False
SESSION_SAVE_EVERY_REQUEST = False
SESSION_SERIALIZER = 'openedx.core.lib.session_serializers.PickleV2Serializer'
SESSION_SERIALIZER = 'openedx.core.lib.session_serializers.PickleSerializer'
SESSION_COOKIE_DOMAIN = ""
SESSION_COOKIE_NAME = 'sessionid'

View File

@@ -153,7 +153,7 @@ class process_cached(object): # pylint: disable=invalid-name
def zpickle(data):
"""Given any data structure, returns a zlib compressed pickled serialization."""
return zlib.compress(pickle.dumps(data, 2)) # Keep this constant as we upgrade from python 2 to 3.
return zlib.compress(pickle.dumps(data, 4)) # Keep this constant as we upgrade from python 2 to 3.
def zunpickle(zdata):

View File

@@ -5,18 +5,17 @@ import pickle
import six
class PickleV2Serializer(object):
class PickleSerializer(object):
"""
Lock the pickle serializer to version 2 of the protocol
because we don't want python 2 to be able to read session
data written by python3 while both are running at the same
time in production.
Set the pickle protocol version explicitly because we don't want
to have session thrashing when we upgrade to newer versions of
python.
Based on the PickleSerializer built into django:
https://github.com/django/django/blob/master/django/contrib/sessions/serializers.py
"""
protocol = 2
protocol = 4
def dumps(self, obj):
"""
@@ -28,10 +27,4 @@ class PickleV2Serializer(object):
"""
Return a python object from pickled data.
"""
if six.PY2:
# Params used below don't exist in python 2
return pickle.loads(data)
else:
# See notes here about pickling python2 objects in python3
# https://docs.python.org/3/library/pickle.html#pickle.Unpickler
return pickle.loads(data, encoding='latin1') # pylint: disable=unexpected-keyword-arg
return pickle.loads(data)