Skip to content

Commit 5f740a4

Browse files
committed
Update pickle protocol detection in bin/update to match bin/check_db
1 parent a34f1d4 commit 5f740a4

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

bin/update

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -880,21 +880,33 @@ def upgrade(mlist):
880880
config_path = os.path.join(mlist._full_path, 'config.pck')
881881
if os.path.exists(config_path):
882882
with open(config_path, 'rb') as fp:
883-
# Try to load the pickle file with multiple encodings
883+
# Try loading with UTF-8 first, then fall back to latin1
884884
try:
885-
# Try UTF-8 first for newer files
885+
fp.seek(0)
886886
data = pickle.load(fp, fix_imports=True, encoding='utf-8')
887-
protocol = pickle.format_version
888-
except (UnicodeDecodeError, pickle.UnpicklingError):
889-
# Fall back to latin1 for older files
887+
if hasattr(data, '_protocol'):
888+
protocol = data._protocol
889+
print(C_('List %(listname)s config.pck uses pickle protocol %(protocol)d') % {
890+
'listname': mlist.internal_name(),
891+
'protocol': protocol
892+
})
893+
else:
894+
print(C_('List %(listname)s config.pck protocol version not stored in data') % {
895+
'listname': mlist.internal_name()
896+
})
897+
except UnicodeDecodeError:
890898
fp.seek(0)
891899
data = pickle.load(fp, fix_imports=True, encoding='latin1')
892-
protocol = pickle.format_version
893-
894-
print(C_('List %(listname)s config.pck uses pickle protocol %(protocol)d') % {
895-
'listname': mlist.internal_name(),
896-
'protocol': protocol
897-
})
900+
if hasattr(data, '_protocol'):
901+
protocol = data._protocol
902+
print(C_('List %(listname)s config.pck uses pickle protocol %(protocol)d') % {
903+
'listname': mlist.internal_name(),
904+
'protocol': protocol
905+
})
906+
else:
907+
print(C_('List %(listname)s config.pck protocol version not stored in data') % {
908+
'listname': mlist.internal_name()
909+
})
898910
except Exception as e:
899911
print(C_('Warning: Could not determine pickle protocol version: %(error)s') % {
900912
'error': str(e)

0 commit comments

Comments
 (0)