Alek Kowalczyk wrote:

I have subscribed to the ObjectAddedEvent for my OrderedContainer.
There is the a strange behavior in the event handler:
- myObj is my contained object
- myObj.__parent__ is my OrderedContainer.

1. this returns True when called in the event handler:
myObj.__name__ in myObj.__parent__
2. this returns False when called in the event handler:
myObj.__name__ in myObj.__parent__.keys()

Code inspection of OrderedContainer.__setitem__ shows the following:
1. first call setitem, which triggers event as side effect
setitem(self, self._data.__setitem__, key, object)

2. after that add key to the _order, which is returned by keys() method:
if not existed:

Is it bug or just works-as-designed? I think that this behavior is improper or at least confusing a bit. Event should be called *after* the keys() method is able to return list with added object, so that: (myObj.__name__ in myObj.__parent__) == (myObj.__name__ in myObj.__parent__.keys())

Yes. I think

        if not existed:

should be executed before

        setitem(self, self._data.__setitem__, key, object)

Perhaps you can round up a patch, including a test that tests this from an event handler perspective? You can submit the patch and the original bug report to the Zope 3 bug collector (

-- -- Professional Zope documentation and training
Next Zope 3 training at Camp5:

Zope3-users mailing list

Reply via email to