[Zope3-Users] updating a zodb with a SchemaManager

Lorenzo Gil Sánchez lgs at sicem.biz
Wed Mar 5 08:32:40 EST 2008


Hi,

I've been using a zope.app.generations.interfaces.ISchemaManager to keep
my database up to date with respect to the changes in the models of my
application and everything is well so far.

Now I have a tricky situation. My model had an attribute and now I
changed that attribute to be read only.

Before:
-------

class IModel(Interface):

  attr1 = zope.schema.TextLine()

class Model(Persistent):
  implements(IModel)

  def __init__(self, attr1=None):
    self.attr1 = attr1

After:
------

class IModel(Interface):

  attr1 = zope.schema.TextLine(readonly=True)
  attr2 = zope.schema.TextLine()

class Model(Persistent):
  implements(IModel)

  def __init__(self, attr2=None):
    self.attr2 = attr2

  def _getAttr1(self):
    return self.attr2.lower()
  attr1 = property(_getAttr1)

As you can see, now attr1 is a computed attribute from attr2.

When updating the old Model objects I add the 'attr2' attribute but I
can't remove the old 'attr1' attribute since is still defined in Model
but is a totally different thing.

I can forget about removing the 'attr1' attribute and things keep
working well. The problem is a waste of space in the database since that
information is still there but impossible to retrieve, right?

I have a related question: is attr1 still saved in the database in the
newer version no matter is a read only python property or does the ZODB
handle this case? As far as I know ZODB only skip those attributes
beginning with _v_ (for volatile), but don't know what it does with
python properties...

Has anyone ever reached a similar situation? Any solution?

Best regards

Lorenzo



More information about the Zope3-users mailing list