[Zope-dev] ComputedAttribute, Persitent and "too many datafull base classes"

Godefroid Chapelle gotcha@swing.be
Sat, 20 Oct 2001 15:44:13 +0200


Hi,

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]))

where at first I defined ContextComputed Attribute like this:

     import ComputedAttribute

     _ComputedAttribute = ComputedAttribute.ComputedAttribute
     del ComputedAttribute

     class ContextComputedAttribute(_ComputedAttribute):
         pass


This put the Folder in a bad state : when I access it later, the Zope 
instance crashes.

So I supposed I needed to use a persistent Attribute and I tried with 
ContextComputedAttribute class defined like this:

     class ContextComputedAttribute(Persistent):
         def __init__(self, test):
             pass


In this case, the Folder stays in a good state but it does not fullfill the 
requirements as ContextComputedAttribute does not descend from the real 
Zope ComputedAttribute class.

My problem is the following :

I cannot define a class like this:

     import ComputedAttribute

     _ComputedAttribute = ComputedAttribute.ComputedAttribute
     del ComputedAttribute

     class ContextComputedAttribute(_ComputedAttribute, Persistent):
           pass

In this case, I get the following error

TypeError: too many datafull base classes

which has to do with too many ExtensionClass derivation...

Can someone tell me how to define a class with both ComputedAttribute and 
Persistent behaviours ?

Thanks a lot.


--

Godefroid Chapelle

BubbleNet sprl
rue Victor Horta, 30
1348 Louvain-la-Neuve
Belgium

Tel + 32 (10) 457490
Mob + 32 (477) 363942

TVA 467 093 008
RC Niv 49849