Strategies for backwards compatibility when using pickle?

Discussion in 'Python' started by duncan, May 3, 2004.

  1. duncan

    duncan Guest

    I am working on an application that currently uses a simple pickle to
    save a project to disk.

    Every time we make a significant change to our object model we tell our
    beta users to delete all of their old projects.

    Does anyone have any advice on how to balance the conflicting interests
    of the developers who want to keep evolving the object model and users
    who need stable project persistance?

    It has been suggested that there may be a way to override pickle to deal
    with an evolving object model but it would be nice to hear from others
    who have tried to handle this problem.

    Thanks

    Duncan
     
    duncan, May 3, 2004
    #1
    1. Advertising

  2. "duncan" <> wrote in
    news::

    > I am working on an application that currently uses a simple pickle to
    > save a project to disk.
    >
    > Every time we make a significant change to our object model we tell our
    > beta users to delete all of their old projects.
    >
    > Does anyone have any advice on how to balance the conflicting interests
    > of the developers who want to keep evolving the object model and users
    > who need stable project persistance?


    i sometimes use .ini files and the config parser o store program settings,
    but thats no option if you need to store entire object hierarchies.
    the ini files are at least tolerant to new or removed values and easy to
    edit by hand, sometimes i pickle and hexlify objects to store them in the
    ini file too, but then i only do that with built in types to avoid such
    problems you mention above.

    > It has been suggested that there may be a way to override pickle to deal
    > with an evolving object model but it would be nice to hear from others
    > who have tried to handle this problem.


    yep, especialy __getstate__ and __setstate__ are interesting for you. by
    implementing __setstate__ you can filter and update the pickled dictionary
    before you assign it to the new instance. thats a good way to convert old
    data to new objects.

    http://python.org/doc/lib/pickle-inst.html

    chris

    --
    Chris <>
     
    Chris Liechti, May 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sonny
    Replies:
    7
    Views:
    375
    Roger Leigh
    Feb 10, 2004
  2. Jason Mobarak
    Replies:
    1
    Views:
    264
    =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=
    Jul 3, 2004
  3. Orestis Markou
    Replies:
    1
    Views:
    314
    Martin v. Löwis
    Oct 8, 2008
  4. Joseph Benik
    Replies:
    12
    Views:
    166
    James F. Hranicky
    Dec 23, 2003
  5. Brian Candler
    Replies:
    9
    Views:
    163
    John Doxey
    May 6, 2009
Loading...

Share This Page