Lorenzo Gil Sanchez wrote:


I have a question about updating the objects in a ZODB. Suppose I already have 100 objects of class A and then I modify class A adding a new attribute. Then I craete a new object of the class A and now I have two kind of instances of my class A, the old ones and the new one.

How do I update the old objects and add the new attribute to them? I can provide a default value for this attribute if that helps.

You can just add the new variables as a class variable.

class SomeOldClass:

   newVar = ''


Or you can make a mixin class for compatibility. This can make your code a bit more readable.

class Compatibility:

   # added in ver. 1.1
   newVar = ''

class SomeOldClass(Compatibility):


Or you can use setter and getter methods.

class Compatibility:

   def getNewVar():
       return geatattr(self, newVar, '')


hilsen/regards Max M, Denmark

IT's Mad Science

Zope3-users mailing list

Reply via email to