Merge lp:~cjwatson/loggerhead/marshal-version into lp:loggerhead

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 516
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~cjwatson/loggerhead/marshal-version
Merge into: lp:loggerhead
Diff against target: 24 lines (+5/-2)
1 file modified
loggerhead/changecache.py (+5/-2)
To merge this branch: bzr merge lp:~cjwatson/loggerhead/marshal-version
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+406291@code.launchpad.net

Commit message

Make RevInfoDiskCache use a marshal version supported by Python 2.

Description of the change

Otherwise we run into trouble in the middle of an upgrade to Python 3, as marshal.dumps produces output that Python 2's marshal.loads can't read.

Since we now have some existing cached data unreadable by Python 2, I also made marshal.loads errors non-fatal and we just pretend we have no cache in such cases; this is OK because it's a cache.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/changecache.py'
2--- loggerhead/changecache.py 2018-10-20 15:14:09 +0000
3+++ loggerhead/changecache.py 2021-07-28 10:25:43 +0000
4@@ -130,7 +130,10 @@
5 elif str(row[0]) != revid:
6 return None
7 else:
8- return marshal.loads(zlib.decompress(row[1]))
9+ try:
10+ return marshal.loads(zlib.decompress(row[1]))
11+ except (EOFError, ValueError, TypeError):
12+ return None
13
14 def set(self, key, revid, data):
15 if not isinstance(key, bytes):
16@@ -140,7 +143,7 @@
17 try:
18 self.cursor.execute(
19 'delete from data where key = ?', (dbapi2.Binary(key), ))
20- blob = zlib.compress(marshal.dumps(data))
21+ blob = zlib.compress(marshal.dumps(data, version=2))
22 self.cursor.execute(
23 "insert into data (key, revid, data) values (?, ?, ?)",
24 list(map(dbapi2.Binary, [key, revid, blob])))

Subscribers

People subscribed via source and target branches