[Checkins] SVN: zope.container/trunk/ fix a really nasty bug in OrderedContainer that occurs with duplication errors (now key errors).

Paul Carduner paulcarduner at gmail.com
Fri May 15 18:10:08 EDT 2009


Log message for revision 99988:
  fix a really nasty bug in OrderedContainer that occurs with duplication errors (now key errors).

Changed:
  U   zope.container/trunk/CHANGES.txt
  U   zope.container/trunk/src/zope/container/ordered.py

-=-
Modified: zope.container/trunk/CHANGES.txt
===================================================================
--- zope.container/trunk/CHANGES.txt	2009-05-15 22:07:43 UTC (rev 99987)
+++ zope.container/trunk/CHANGES.txt	2009-05-15 22:10:08 UTC (rev 99988)
@@ -4,6 +4,9 @@
 
 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

Modified: zope.container/trunk/src/zope/container/ordered.py
===================================================================
--- zope.container/trunk/src/zope/container/ordered.py	2009-05-15 22:07:43 UTC (rev 99987)
+++ zope.container/trunk/src/zope/container/ordered.py	2009-05-15 22:10:08 UTC (rev 99988)
@@ -179,6 +179,13 @@
         ['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 @@
         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



More information about the Checkins mailing list