Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'subject:skip:s 10': 0.05; 'constructor': 0.07; 'suppose': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '(but': 0.15; '"default"': 0.16; '__version__': 0.16; 'argument.': 0.16; 'attribute,': 0.16; 'necessary).': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'used:': 0.16; 'instance': 0.17; '(in': 0.18; 'handles': 0.18; 'appropriate': 0.20; 'define': 0.20; 'issue.': 0.20; 'defined': 0.22; "python's": 0.23; 'header:User-Agent:1': 0.26; 'wonder': 0.27; 'header:X-Complaints-To:1': 0.28; 'writes:': 0.29; 'objects': 0.29; 'class': 0.29; 'expect': 0.31; 'could': 0.32; 'cases,': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'recommended': 0.33; 'version': 0.34; 'adds': 0.35; 'protocol': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'useful': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'level': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'further': 0.61; 'provide': 0.62; 'more': 0.63; 'strategy': 0.64; 'received:217': 0.68; 'pickled': 0.84; 'imagine': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dieter Maurer Subject: Re: serialization and versioning Date: Sat, 13 Oct 2012 08:23:14 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0878a.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:CHlrB06InKm1awuvNk01XDqjo4Y= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350109409 news.xs4all.nl 6905 [2001:888:2000:d::a6]:32843 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31185 Neal Becker 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