[Zope3-Users] Re: OrderedContainer.keys() does not return newely
added key in ObjectAddedEvent
Philipp von Weitershausen
philipp at weitershausen.de
Tue Feb 20 13:53:14 EST 2007
Alek Kowalczyk wrote:
> Hi,
>
> 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:
> self._order.append(key)
>
> 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:
self._order.append(key)
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
(http://www.zope.org/Collectors/Zope3-dev).
--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
More information about the Zope3-users
mailing list