Commit 19102482 authored by Paul Carduner's avatar Paul Carduner

fix a bug where exceptions thrown during __setitem__ for an ordered container...

fix a bug where exceptions thrown during __setitem__ for an ordered container leaves a bad key in the ordering.
parent 90ea53ce
......@@ -5,7 +5,8 @@ CHANGES
3.6.1dev (unreleased)
---------------------
- Bug: Error thrown during __setitem__ for an ordered container leaves
bad key in order
- fixed #238579 / #163149: error with unicode traversing
- fixed #221025 : adding menu is sorted with translated item
by using a collator (better localized sorting)
......
......@@ -204,7 +204,11 @@ class OrderedContainer(Persistent, Contained):
self._order.append(key)
# This function creates a lot of events that other code listens to.
setitem(self, self._data.__setitem__, key, object)
try:
setitem(self, self._data.__setitem__, key, object)
except Exception, e:
self._order.remove(key)
raise e
return key
......
......@@ -89,6 +89,43 @@ def test_all_items_available_at_object_added_event():
>>> setup.placefulTearDown()
"""
def test_exception_causes_order_fix():
"""
Prepare the setup::
>>> root = setup.placefulSetUp(site=True)
Now register an event subscriber to object added events that
throws an error.
>>> import zope.component
>>> from zope.app.container import interfaces
>>> @zope.component.adapter(interfaces.IObjectAddedEvent)
... def raiseException(event):
... raise Exception()
>>> zope.component.provideHandler(raiseException)
Now we are adding an object to the container.
>>> from zope.app.container.ordered import OrderedContainer
>>> oc = OrderedContainer()
>>> oc['foo'] = 'FOO'
Traceback (most recent call last):
...
Exception
The key 'foo' should not be around:
>>> 'foo' in oc.keys()
False
Finally, tear down::
>>> setup.placefulTearDown()
"""
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite("zope.app.container.ordered",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment