pickle and module versioning

dieter dieter at handshake.de
Tue Dec 18 03:15:48 EST 2018


Neal Becker <ndbecker2 at gmail.com> writes:
> ...
> Has anyone else run into this issue

People who use the "ZODB" (= "Zope Object DataBase")
are familiar with it.

> and have any ideas?

There are things, you must not do. In the "ZODB" case, for example,
you must not change whether the class inherits from "persistent.Persistent"
or not.

For other things, there are workarounds:

 * you can use "module" aliases and/or class aliases inside a module
   to handle changes in the package/class structure

 * you can register a "class factory" to provide a "default class"
   for a class not found -- this way, you have at least
   access to the data event though the replacement class
   does not understand it.

 * if a (new) class is found, it must be able to cope
   with the (old) data. You may need to provide
   an appropriate "__setstate__" in the (new) class
   to make this possible.

 * objects created from old data may lack attributes
   which objects created after a class change have.
   You can either add them in "__setstate__" or provide
   default values in the class

 * if you plan drastical changes, migrate your data using
   a different serialization.

   An example is e.g. a switch from "ZODB on Python 2" to
   "ZODB on Python 3". One approach in this case
   is to use "collective.transmogrifier".
   See "https://docs.plone.org/develop/import/index.html#collective-transmogrifier" for details.




More information about the Python-list mailing list