deo at plonesolutions
Jan 18, 2005, 3:12 PM
Post #1 of 7
SEGFAULT using ComputedAttribute
I'm working to improve the reliability of ExternalStorage, an
Archetypes addon who provides a filesystem storage that can be
used (in theory) for any field.
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
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.
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
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 and from ExternalStorage trunk, changing
initializeField method as above and running the tests.
I can provide any additional info on request.
Thanks for your attention.
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