Skip to content

Commit

Permalink
Fix nasty acquisition related bug that would trigger if an aq-wrapped…
Browse files Browse the repository at this point in the history
… object had a proper __parent__ pointer and one of its parents did not, leading to infinite recursion
  • Loading branch information
optilude committed Jun 18, 2009
1 parent f47aec5 commit ed0db64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,14 @@ Changelog
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
Expand Down
11 changes: 6 additions & 5 deletions src/five/localsitemanager/utils.py
@@ -1,7 +1,7 @@
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
Expand All @@ -16,12 +16,13 @@ def get_parent(obj):
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)

0 comments on commit ed0db64

Please sign in to comment.