At 03:44 PM 10/20/01 +0200, Godefroid Chapelle wrote:
>In a product I am writing, I am trying to add a ComputedAttribute to an 
>instance of a Folder descendant class.
>This is the code I use:
>     def addComputedAttribute(self, attributeName, sourceCode):
>         methodName = '_ca_get%s' % attributeName
>         self.addMethod(methodName, sourceCode)
>         setattr(self, attributeName, 
> ContextComputedAttribute(self.__class__.__dict__[methodName]))

I think the problem you're having is that the method object being used in 
the last line (i.e., self.__class__.__dict__[methodName]) is not 
persistent.  If it is a Python function, it will not be saved persistently 
within the computed attribute.  This is probably why the Zope instance 
crashes at a later time.

This doesn't have anything to do with whether ComputedAttribute is 
Persistent.  It doesn't need to be, which is a good thing because you can't 
derive a class from both (as you've discovered).  You can write a Python 
version of ComputedAttribute by deriving only from Persistent, but as I 
said there is really no need to do that.  You need the function to be 
persistent, not the ComputedAttribute itself.  If the function is currently 
a pure-Python function, you need to replace it with some kind of callable 
object that can be pickled, such as a PythonScript.  You could also write 
your own class to do this, but again it is not the ComputedAttribute part 
that would cause a problem.

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to