Hi All,

I have some data that I want to store as annotations on an object
(currently using IAttributeAnnotations), and I want to use
FieldProperty objects to provide default values and validation. In
general, this works flawlessly. I can create a new object, and edit
it's properties. Unfortunately, if I create new object, view it's
properties, then attempt to view it's properties again, I get a
maximum recursion exceeded error. I assume there is something about
the way the init function is constructed that is causing this. Here's
how it works generally:

KEY = "demographicinfo"

def getterAndSetter(key):
    def getter(self):
        return self.mapping[key]
    def setter(self, obj):
        self.mapping[key] = obj
    return getter, setter
class DemographicInfo(object):
    def getAnnotations(self):
        annotations = IAnnotations(self.context)
        return annotations
    def __init__(self, context):
        self.context = context
        annotations = self.getAnnotations()
        mapping = annotations.get(KEY)
        if mapping is None:
            blank = {}
            blank['birth_date'] = FieldProperty(IDemographicInfo['birth_date'])
            blank['sex'] = FieldProperty(IDemographicInfo['sex'])
            mapping = annotations[KEY] = blank
        self.mapping = mapping
    birth_date = property(*getterAndSetter('birth_date'))
    sex = property(*getterAndSetter('sex'))

It appears to be the getter method that is causing the trouble, but I
can't really be sure.

I would appreciate any advise on this.


Alec Munro
Zope3-users mailing list

Reply via email to