[Checkins] SVN: zope.container/trunk/ Be more forgiving when trying to remove broken objects
Patrick Gerken
do3ccqrv at gmail.com
Tue Sep 20 20:08:25 EST 2011
Log message for revision 122862:
Be more forgiving when trying to remove broken objects
Changed:
U zope.container/trunk/CHANGES.txt
U zope.container/trunk/src/zope/container/contained.py
-=-
Modified: zope.container/trunk/CHANGES.txt
===================================================================
--- zope.container/trunk/CHANGES.txt 2011-09-20 17:56:07 UTC (rev 122861)
+++ zope.container/trunk/CHANGES.txt 2011-09-21 01:08:24 UTC (rev 122862)
@@ -8,9 +8,12 @@
- 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)
-------------------
Modified: zope.container/trunk/src/zope/container/contained.py
===================================================================
--- zope.container/trunk/src/zope/container/contained.py 2011-09-20 17:56:07 UTC (rev 122861)
+++ zope.container/trunk/src/zope/container/contained.py 2011-09-21 01:08:24 UTC (rev 122862)
@@ -640,6 +640,19 @@
>>> 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 @@
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:
More information about the checkins
mailing list