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

Steve Alexander [email protected]
Thu, 26 Jul 2001 18:56:39 +0100


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:

   def __set_attr__(self,name,val,_v_dm_=_v_dm_):
        try:
            dm = self.__dict__[_v_dm_]
            self = self._canonicalForm()
        except KeyError:
            if name in ('id', '__name__'):
                self.__dict__[name]=val
                self._p_changed = 1
                return
            raise

        self._objectChanging(name)

--
Steve Alexander
Software Engineer
Cat-Box limited