Commit 1e58ec7f authored by Marius Gedminas's avatar Marius Gedminas

Fix a bug that made it impossible to store None values in containers

(LP#1070719).
parent 7a2af522
......@@ -21,6 +21,9 @@ CHANGES
- Handle Broken Objects more gracefully
- Fix a bug that made it impossible to store None values in containers
(LP#1070719).
3.12.0 (2010-12-14)
-------------------
......
......@@ -331,6 +331,8 @@ def notifyContainerModified(object, *descriptions):
"""Notify that the container was modified."""
notify(ContainerModifiedEvent(object, *descriptions))
_SENTINEL = object()
def setitem(container, setitemf, name, object):
"""Helper function to set an item and generate needed events
......@@ -547,10 +549,10 @@ def setitem(container, setitemf, name, object):
if not name:
raise ValueError("empty names are not allowed")
old = container.get(name)
old = container.get(name, _SENTINEL)
if old is object:
return
if old is not None:
if old is not _SENTINEL:
raise KeyError(name)
object, event = containedEvent(object, container, name)
......
......@@ -122,6 +122,27 @@ def test_exception_causes_order_fix():
"""
def test_adding_none():
"""Test for OrderedContainer
This is a regression test: adding None to an OrderedContainer
used to corrupt its internal data structure (_order and _data
wouldl get out of sync, causing KeyErrors when you tried to iterate).
>>> from zope.container.ordered import OrderedContainer
>>> oc = OrderedContainer()
>>> oc['foo'] = None
>>> oc.keys()
['foo']
>>> oc.values()
[None]
>>> oc.items()
[('foo', None)]
>>> print oc['foo']
None
"""
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite("zope.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