[Zope] Zope (X)3 FAQ
Thomas Guettler
Thomas Guettler <thomas@thomas-guettler.de>
Sat, 5 Apr 2003 18:23:05 +0200
On Sat, Apr 05, 2003 at 08:06:40AM -0500, Stephan Richter wrote:
> On Saturday 05 April 2003 07:37, Thomas Guettler wrote:
> > On Fri, Apr 04, 2003 at 07:35:19PM -0500, Stephan Richter wrote:
> > > Hello everyone,
> > >
> > > I just updated the Zope 3 FAQ at:
> > > http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/FAQ
> >
> > New question:
> >
> > Will there be a "standard" way of updating existing instances to
> > changes in the python source?
> >
> > Upto now I my python classes have a refresh() method wich updates
> > instances which are already in ZODB. I prefere this explizit method to
> > the implicit update when the object gets unpickled.
>
> I think you are using Zope wrong. You do not need such a methid, the
> Transaction machinery does it for you. If you have a dictionary, you should
> use persistent dictionary, so it will be updated.
No, you missunderstood me.
Example: You created instances of you class Foo. You have about 1000
instances of this in the ZODB. Now you change the source of your
python code, that all *new* objects get a birthday:
new code:
class Foo:
def __init__(self):
self.birthday=time.time()
If your application is already used by some people, you can't delete
the 1000 existing objects which don't have a birthday. You need a way
to update them. In this example you need to set the birthday for the
old objects.
You could set the birthday in __setstate__(). This is called when the
objects gets unpickled. But I had problems with it. I think it is
because the objects in memory are already unpickled, thus they don't
get updated.
The solution is quite easy: All objects have a refreshAllObjects()
method, which gets called from me if you do relevant changes. OK, this
does not scale since all objects are touched, but it works for my
use-case.
I hope you understood what I mean. If not, please ask!
thomas
--
Thomas Guettler <guettli@thomas-guettler.de>
http://www.thomas-guettler.de