[Zope-dev] ZPatterns -- trigger add events not working

Steve Alexander steve@cat-box.net
Wed, 12 Jul 2000 16:09:15 +0100


Steve Alexander wrote:
> 
> "Phillip J. Eby" wrote:
> >
> > This would explain why you only get a change event, since if add happens
> > after change, it is ignored.  I'm curious how the change event is getting
> > called first, since...  Oh.  I'll bet I know what it is.  It's probably
> > that manage_afterAdd is being called later in the ObjectManager code than
> > it used to be, and/or Zope is trying to set an _owner attribute on the
> > newly added object.  Crap.  This is going to take some rethinking to find
> > another way to trap the Zope "add" event.  :(
> 
> If it saves you any time, here's part of a traceback from an exception
> raised in _objectChanging():
> 
> File /lib/python/ZClasses/ZClass.py, line 466, in createInObjectManager
> File /lib/python/OFS/ObjectManager.py, line 258, in _setObject
> File /lib/python/AccessControl/Role.py, line 393, in
> manage_setLocalRoles
> 
> Looks like you're right -- manage_setLocalRoles.

I have patched the _objectAdding method of class Agent in Agents.py:

    def _objectAdding(self,client, _id=_id):
        print "_objectAdding"
        i = _id(client)
        l = self._v_tranlog
        c = l.get(i)

        if c is None:
            l[i] = AddedStatus, client, None
            return

        s,c,m = c
        # XXX Hack to make "add" triggers work
        if s is ChangedStatus:
            l[i] = AddedStatus, client, m
        # XXX

        if s is DeletedStatus:
            l[i] = ChangedStatus, client, m

        return

I'm not sure whether this will have any nasty side-effects though.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net