Commit a211c624 authored by Paul Carduner's avatar Paul Carduner

fix a really nasty bug in OrderedContainer that occurs with duplication errors (now key errors).

parent 2722d446
......@@ -4,6 +4,9 @@ CHANGES
3.8.2 (unreleased)
------------------
- Fix a bug in OrderedContainer where trying to set the value for a
key that already exists (duplication error) would actually delete the
key from the order, leaving a dangling reference.
- Partially break dependency on ``zope.traversing`` by disusing
zope.traversing.api.getPath in favor of using
......
......@@ -179,6 +179,13 @@ class OrderedContainer(Persistent, Contained):
['foo', 'baz']
>>> int(len(oc._order) == len(oc._data))
1
>>> oc['foo'] = 'baz'
Traceback (most recent call last):
...
KeyError: u'foo'
>>> oc._order
['foo', 'baz']
"""
existed = self._data.has_key(key)
......@@ -207,7 +214,8 @@ class OrderedContainer(Persistent, Contained):
try:
setitem(self, self._data.__setitem__, key, object)
except Exception, e:
self._order.remove(key)
if not existed:
self._order.remove(key)
raise e
return key
......
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