[ZPatterns] Problem in latest ZPatterns: setattr, id, etc.

Phillip J. Eby pje@telecommunity.com
Mon, 13 Aug 2001 12:07:44 -0500


At 06:56 PM 7/26/01 +0100, Steve Alexander wrote:
>There's a problem with the latest ZPatterns. I'm only using Zope 2.4 now, 
>so I can't easily verify that there's a problem on earlier Zopes.
>
>The problem is with DataSkin.py
>
>The old __init__ method looks like this:
>
>   def __init__(self, id):
>       # Bypass attribute providers for setting up initial id,
>       # since they need the id in order to work!
>       self.__dict__['id']=id; self._p_changed = 1
>
>This is changed to:
>
>   def __init__(self, id=None):
>       # we could ditch this whole method except for backward
>       # compatibility  :(
>       pass
>
>However, the start of __setattr__ still looks like this:
>
>   def __set_attr__(self,name,val,_v_dm_=_v_dm_):
>        try:
>            dm = self.__dict__[_v_dm_]
>        except KeyError:
>            if name=='id' and val==self.__dict__['id']: return
>            raise
>
>        self = self._canonicalForm()
>
>The problem is that the above code gets called before __of__ has been 
>called, so there is no _v_parent, so you get a KeyError looking up 
>__dict__[_v_parent] in the _canonicalForm method of DataSkin.
>
>I think the start of __set_attr__ should look like this:

I've checked something similar into CVS.  The main difference is that the 
version I've checked in maintains the same behavior as the old for 
situations where the _v_dm_ is not set.  Basically, my version of the patch 
skips the canonical form lookup, objectChanging call, and attribute 
provider delegation if _v_parent is not set, falling through to the default 
persistent attribute setting code.