Commit 6d8039d9 authored by Patrick Gerken's avatar Patrick Gerken

Be more forgiving when trying to remove broken objects

parent e2ee27e4
......@@ -8,7 +8,10 @@ CHANGES
- Send ``IContainerModifiedEvent`` *after* the container is modified
(LP#705600).
- Preserve the original exception traceback in OrderedContainer.__setitem__.
- Preserve the original exception traceback in
OrderedContainer.__setitem__.
- Handle Broken Objects more gracefully
3.12.0 (2010-12-14)
......
......@@ -640,6 +640,19 @@ def uncontained(object, container, name=None):
>>> len(getEvents(IObjectModifiedEvent))
3
If one tries to delete a Broken object, we allow them to do
just that.
>>> class Broken(object):
... __Broken_state__ = {}
>>> broken = Broken()
>>> broken.__Broken_state__['__name__'] = u'bar'
>>> broken.__Broken_state__['__parent__'] = container
>>> container[u'bar'] = broken
>>> uncontained(broken, container, u'bar')
>>> len(getEvents(IObjectRemovedEvent))
2
"""
try:
oldparent = object.__parent__
......@@ -647,10 +660,15 @@ def uncontained(object, container, name=None):
except AttributeError:
# The old object doesn't implements IContained
# Maybe we're converting old data:
if not fixing_up:
raise
oldparent = None
oldname = None
if hasattr(object, '__Broken_state__'):
state = object.__Broken_state__
oldparent = state['__parent__']
oldname = state['__name__']
else:
if not fixing_up:
raise
oldparent = None
oldname = None
if oldparent is not container or oldname != name:
if oldparent is not None or oldname is not None:
......
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