[Zope3-Users] Infinite recursion when storing FieldProperties in as annotations (using IAttributeAnnotations).

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Aug 28 19:15:13 EDT 2005


On Wednesday 24 August 2005 15:22, Alec Munro wrote:
> 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):
>     implements(IDemographicInfo)
>    
>     def getAnnotations(self):
>         annotations = IAnnotations(self.context)
>         return annotations

This is overkill. You only call this method in the constructor.

>     def __init__(self, context):
>         self.context = context
>         annotations = self.getAnnotations()
>         mapping = annotations.get(KEY)
>         if mapping is None:
>             blank = {}

This needs to be a persistent dictionary.

>             blank['birth_date'] =
> FieldProperty(IDemographicInfo['birth_date']) blank['sex'] =
> FieldProperty(IDemographicInfo['sex'])

I am 80% sure this is your problem. Properties are meant to be used as 
attributes on classes, not as items in a dictionary/mapping.

>             mapping = annotations[KEY] = blank
>         self.mapping = mapping
>            
>     birth_date = property(*getterAndSetter('birth_date'))
>     sex = property(*getterAndSetter('sex'))

This all seems convoluted to me. I think you would be better off with a 
__getattr__ and __setattr__ in the adapter that manually does the validation.

At least this would be my suggestion.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list