[Zope] Upgrading a product

Michel Pelletier michel@digicool.com
Wed, 15 Dec 1999 13:09:12 -0500


> -----Original Message-----
> From: rgines@purina.com [mailto:rgines@purina.com]
> Sent: Wednesday, December 15, 1999 12:06 PM
> To: zope@zope.org
> Subject: [Zope] Upgrading a product
> 
>
> Here is the question.   Our new version has new methods, 
> properties and
> controls for the container and new objects for the container 
> now have new
> properties to them.    So that users of this product do not 
> need to start
> from scratch, how would the old (version1) objects get 
> upgraded to match
> new objects created under our new version 2 of the product?  
> I can think of
> a few methods that all seem very ugly to me.   I was hoping 
> that someone
> has thought through this and may have some suggestions.

Good Question!  The answer is with __setstate__.

The old instances of your objects will have their __setstate__ methods
called when they are activated from the database into memory.  These are
instances created with the _old_ code.  But when they are activated,
their _new_ setstate is called (because you just upgraded, right?) and
that method can be prepared to take any action it wants to 'upgrade' the
instance.  Often this includes defining new instance variables and
manipulating the object in some way by calling methods on 'self'.

If your product is ZClass based, your ZClass can subclass a Python class
that defines a __setstate__ for your ZClass.

-Michel
> 
> Thanks a bunch.
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
>           No cross posts or HTML encoding!
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>