launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26398
[Merge] ~cjwatson/launchpad:pickle-protocol-2 into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:pickle-protocol-2 into launchpad:master.
Commit message:
Fix pickle protocol to 2
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398534
This ensures compatibility with Python 2, so that when we start upgrading production systems to Python 3 we won't cause problems for systems still on Python 2.
I left lp.services.testing.profiled alone, since that's only for communication between test processes.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:pickle-protocol-2 into launchpad:master.
diff --git a/lib/launchpad_loggerhead/session.py b/lib/launchpad_loggerhead/session.py
index f2d3e9b..c78c021 100644
--- a/lib/launchpad_loggerhead/session.py
+++ b/lib/launchpad_loggerhead/session.py
@@ -63,6 +63,7 @@ class SessionHandler(object):
# if the value is non-empty *or* if it was non-empty at the start
# of the request.
if existed or session:
- environ[self.session_var] = pickle.dumps(session)
+ # Use protocol 2 for Python 2 compatibility.
+ environ[self.session_var] = pickle.dumps(session, protocol=2)
return start_response(status, response_headers, exc_info)
return self.application(environ, response_hook)
diff --git a/lib/lp/registry/tests/test_teammembership.py b/lib/lp/registry/tests/test_teammembership.py
index 3d69231..97951d1 100644
--- a/lib/lp/registry/tests/test_teammembership.py
+++ b/lib/lp/registry/tests/test_teammembership.py
@@ -1292,7 +1292,8 @@ class TestCheckTeamParticipationScript(TestCase):
filename_out = tempdir.join("info.out")
fout = bz2.BZ2File(filename_in, "w")
try:
- pickle.dump(info, fout, pickle.HIGHEST_PROTOCOL)
+ # Use protocol 2 for Python 2 compatibility.
+ pickle.dump(info, fout, protocol=2)
finally:
fout.close()
code, out, err = self._runScript(
diff --git a/lib/lp/services/utils.py b/lib/lp/services/utils.py
index 6146e3e..a8de8e0 100644
--- a/lib/lp/services/utils.py
+++ b/lib/lp/services/utils.py
@@ -319,7 +319,8 @@ def save_bz2_pickle(obj, filename):
"""Save a bz2 compressed pickle of `obj` to `filename`."""
fout = bz2.BZ2File(filename, "w")
try:
- pickle.dump(obj, fout, pickle.HIGHEST_PROTOCOL)
+ # Use protocol 2 for Python 2 compatibility.
+ pickle.dump(obj, fout, protocol=2)
finally:
fout.close()
diff --git a/lib/lp/services/webapp/pgsession.py b/lib/lp/services/webapp/pgsession.py
index 5d110af..a7d4db6 100644
--- a/lib/lp/services/webapp/pgsession.py
+++ b/lib/lp/services/webapp/pgsession.py
@@ -196,7 +196,8 @@ class PGSessionPkgData(MutableMapping, PGSessionBase):
def __setitem__(self, key, value):
key = ensure_unicode(key)
- pickled_value = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
+ # Use protocol 2 for Python 2 compatibility.
+ pickled_value = pickle.dumps(value, protocol=2)
self.session_data._ensureClientId()
self.store.execute(