[Checkins] SVN: five.localsitemanager/branches/1.0/ Fix nasty acquisition related bug that would trigger if an aq-wrapped object had a proper __parent__ pointer and one of its parents did not, leading to infinite recursion

Martin Aspeli optilude at gmx.net
Thu Jun 18 05:20:50 EDT 2009


Log message for revision 101122:
  Fix nasty acquisition related bug that would trigger if an aq-wrapped object had a proper __parent__ pointer and one of its parents did not, leading to infinite recursion

Changed:
  U   five.localsitemanager/branches/1.0/CHANGES.txt
  U   five.localsitemanager/branches/1.0/src/five/localsitemanager/utils.py

-=-
Modified: five.localsitemanager/branches/1.0/CHANGES.txt
===================================================================
--- five.localsitemanager/branches/1.0/CHANGES.txt	2009-06-18 08:44:44 UTC (rev 101121)
+++ five.localsitemanager/branches/1.0/CHANGES.txt	2009-06-18 09:20:49 UTC (rev 101122)
@@ -4,6 +4,14 @@
 1.1 - unreleased
 ----------------
 
+* Don't prefer using __parent__ over using aq_parent() to find the parent when
+  looking for a registry. This causes nasty acquisition infinite recursion
+  because doing getattr(obj, '__parent__') when obj supports implicit
+  acquisition gives you back the parent acquisition-wrapped in the child.
+  It's not a problem until some parent *doesn't* have a __parent__ pointer,
+  at which point we end up trying to use aq_parent() and get into a loop.
+  [optilude]
+
 * Made zope.component 3.5 support official and adjusted tests.
 
 1.0 - 2008-11-18

Modified: five.localsitemanager/branches/1.0/src/five/localsitemanager/utils.py
===================================================================
--- five.localsitemanager/branches/1.0/src/five/localsitemanager/utils.py	2009-06-18 08:44:44 UTC (rev 101121)
+++ five.localsitemanager/branches/1.0/src/five/localsitemanager/utils.py	2009-06-18 09:20:49 UTC (rev 101122)
@@ -1,8 +1,8 @@
 from zope.traversing.interfaces import IContainmentRoot
 
 from Acquisition import aq_parent, aq_inner
+from Acquisition.interfaces import IAcquirer
 
-
 def get_parent(obj):
     """Returns the container the object was traversed via.  This
     is a version of zope.traversing.api.getParent that is designed to
@@ -16,12 +16,13 @@
     if IContainmentRoot.providedBy(obj):
         return None
     
+    if IAcquirer.providedBy(obj):
+        parent = aq_parent(aq_inner(obj))
+        if parent is not None:
+            return parent
+        
     parent = getattr(obj, '__parent__', None)
     if parent is not None:
         return parent
 
-    parent = aq_parent(aq_inner(obj))
-    if parent is not None:
-        return parent
-
     raise TypeError("Not enough context information to get parent", obj)



More information about the Checkins mailing list