
deo at plonesolutions
Jan 18, 2005, 3:12 PM
Post #1 of 7
(1847 views)
Permalink
|
|
SEGFAULT using ComputedAttribute
|
|
Hello folks, Introduction ============ I'm working to improve the reliability of ExternalStorage[1], an Archetypes addon who provides a filesystem storage that can be used (in theory) for any field. The problem =========== Some AT pieces rely in the presence of an attribute containing the data it wants to access. This attribute should behave exactly as calling the field accessor method (sorry for the AT specific terminology). Normally, this kind of thing is a trivial task done by ComputedAttribute, to mimics the results of an original method call. When I try to use the ComputedAttribute trick, I make Zope SEGFAULT... :-( Details ======= Considering a schema containing a field 'test', I need to create an attribute 'test' on each instance which use the schema. This new property should have the same value as when calling 'instance.getTest()', which is done by 'field.get()' as we are playing with the 'test' field. Segfaulting =========== I'm setting the new property at field initialization time, as we have all needed elements: self (the storage), instance (the current object instance) and field (our 'test' field): def initializeField(self, instance, field): name = field.getName() if not hasattr(aq_base(instance), name): # This should create a 'test' attribute on the # current instance, with the same value of a # field.get method call setattr(instance, name, ComputedAttribute(field.get, 1)) In fact, it seems to (almost) work as expected, because all the 'functional' (testFuncional.py, where I use 'self.publish()') tests pass. The SEGFAULTs happens when accessing the parent instance, or when doing a copy/paste operation (reproducible at testCopy.py). Probably I'm abusing of ComputedAttribute, but I can't think in any other solution. Any thought is highly appreciated! :-) Reproducing the error ===================== You can reproduce the error with a current checkout from Archetypes release-1_3-branch[2] and from ExternalStorage trunk[1], changing initializeField method as above and running the tests. I can provide any additional info on request. Thanks for your attention. [1]http://cvs.sf.net/viewcvs.py/collective/ExternalStorage [2]http://svn.plone.org/archetypes/Archetypes/branches/release-1_3-branch -- _____________________________________________________________________ Dorneles Treméa · Developer · Plone Solutions · Brazil Consulting · Training · Development · http://www.plonesolutions.com _____________________________________________________________________ Plone Foundation · http://plone.org/foundation · Protecting Plone _______________________________________________ Zope-Coders mailing list Zope-Coders [at] zope http://mail.zope.org/mailman/listinfo/zope-coders
|