Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31185 > unrolled thread

Re: serialization and versioning

Started byDieter Maurer <dieter@handshake.de>
First post2012-10-13 08:23 +0200
Last post2012-10-13 08:23 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: serialization and versioning Dieter Maurer <dieter@handshake.de> - 2012-10-13 08:23 +0200

#31185 — Re: serialization and versioning

FromDieter Maurer <dieter@handshake.de>
Date2012-10-13 08:23 +0200
SubjectRe: serialization and versioning
Message-ID<mailman.2105.1350109409.27098.python-list@python.org>
Neal Becker <ndbecker2@gmail.com> writes:

> I wonder if there is a recommended approach to handle this issue.
>
> Suppose objects of a class C are serialized using python standard pickling.  
> Later, suppose class C is changed, perhaps by adding a data member and a new 
> constructor argument.
>
> It would see the pickling protocol does not directly provide for this - but is 
> there a recommended method?
>
> I could imagine that a class could include a class __version__ property that 
> might be useful - although I would further expect that it would not have been 
> defined in the original version of class C (but only as an afterthought when it 
> became necessary).

The ZODB (Zope Object DataBase) is based on Python's pickle.

In the ZODB world, the following strategy is used:

  *  if the class adds a new data attribute, give it (in addition) a
     corresponding class level attribute acting as "default" value
     in case the pickled state of an instance lacks this
     instance level attribute

  *  for more difficult cases, define an appropriate "__getstate__"
     for the class that handles the necessary model upgrades

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web