[Zope] old instances and new versions of their classes

Mitchell Model model@mpi.com
Thu, 20 Sep 2001 14:12:12 -0400


Is there any way to get existing instances to recognize new or changed methods (or class variables) of their classes?  (I'm not interested in regular instance variables here, just methods and class variables.)

I've seen a couple of mentions of the fact that instances of one of my product classes are instances of a specific version of that class, which doesn't change when I modify the class.  I can also see this in the debugger, since the address shown in printouts such as:

    >>> a.__class__
    <extension class Products.MyProduct.MyClass at 340668>

changes when I reload the class.  I also see that old instances don't know about new methods (or class variables) I add to the class, or even about changed definitions of methods.  (The address of oldInstance.someMethod and newInstance.someMethod are different when someMethod's definition is changed and the class reloaded between creating oldInstance and newInstance.)

While I'm developing, I'm creating objects from scripts, so I can always junk the whole site and recreate everything.  What I'm concerned about, though, is later, as my product evolves, I'm going to want to redefine and add methods and class variables that I'll want my old instances to see.  It isn't much of an object-oriented environment if there's no way to redefine the behavior of an instance's class!

(What happens when new instance variables are added is a different problem, since that relates specifically to instance state, whereas methods and class variables are not stored in instances.  New instance variables are a problem in any kind of object persistence.)

Suggestions?  Comments?