@@ -660,6 +660,12 @@ def __save(self, data_dict):
660660 # we never rotate unless the we've successfully written the temp file.
661661 # We use pickle now because marshal is not guaranteed to be compatible
662662 # between Python versions.
663+ #
664+ # We use protocol 4 for Python 2/3 compatibility because:
665+ # 1. It supports large objects (>4GB)
666+ # 2. It's compatible between Python 2.7 and Python 3.x
667+ # 3. It handles Unicode strings properly
668+ # 4. It's the highest protocol version supported by both Python 2.7 and 3.x
663669 fname = os .path .join (self .fullpath (), 'config.pck' )
664670 fname_tmp = fname + '.tmp.%s.%d' % (socket .gethostname (), os .getpid ())
665671 fname_last = fname + '.last'
@@ -747,7 +753,7 @@ def __load(self, dbfile):
747753 elif dbfile .endswith ('.pck' ) or dbfile .endswith ('.pck.last' ):
748754 def loadfunc (fp ):
749755 try :
750- # Try UTF-8 first for newer files
756+ # Try UTF-8 first for newer files (protocol 4)
751757 return pickle .load (fp , fix_imports = True , encoding = 'utf-8' )
752758 except (UnicodeDecodeError , pickle .UnpicklingError ):
753759 # Fall back to latin1 for older files
@@ -829,6 +835,8 @@ def CheckVersion(self):
829835 """Check the version of the list's config database.
830836
831837 If the database version is not current, update the database format.
838+ This includes ensuring that pickle files are saved with protocol 4
839+ for Python 2/3 compatibility.
832840 """
833841 # Increment this variable when the database format changes. This allows
834842 # for a bit more graceful recovery when upgrading. BAW: This algorithm
@@ -837,6 +845,9 @@ def CheckVersion(self):
837845 # MM3.0.
838846 data_version = getattr (self , 'data_version' , 0 )
839847 if data_version >= mm_cfg .DATA_FILE_VERSION :
848+ # Even if the data version is current, ensure we're using protocol 4
849+ # for pickle files by saving the current state
850+ self .Save ()
840851 return
841852
842853 # Pre-2.1a3 versions did not have a data_version
0 commit comments