[Zope] Change the class of a Zope object
Dieter Maurer
dieter at handshake.de
Thu May 13 16:21:54 EDT 2004
Max M wrote at 2004-5-13 09:30 +0200:
>I have a bunch of objects in the ZODB that I need to convert to other
>objects.
>
>The new object have the same meta_type and the same attributes. But they
>are of a new class.
>
>So I thought that I could simply assign a new class.
>
>I tried assigning the new class to __class__ but that didn't work. Like::
>
> obj.__class__ = SomeNewClass
>
>I suspect that is because I am assigning it to an aquisition wrapper.
>But I am not shure.
>
>Would I need to do something like?
>
> base = obj.aq_base
> base.__class__ = SomeNewClass
It will not work.
For efficiency reasons, the class is not coded only in the object itself
but also in references to the object.
When an object is loaded, it is (usually) loaded via a reference
and this reference determines the class. Thus, you must not only
change the object's class. You must also change all references
to the object.
Probably, you must also tell the object that is has been modified.
--
Dieter
More information about the Zope
mailing list