Skip to content

Commit

Permalink
Raise RuntimeError: Recursion detected in acquisition wrapper if an…
Browse files Browse the repository at this point in the history
… object with a `__parent__` pointer points to a wrapper that in turn points to the original object.
  • Loading branch information
hannosch committed Dec 13, 2011
1 parent 3538634 commit 5a6a6f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,10 @@ Changelog
4.0 (unreleased)
----------------

- Raise `RuntimeError: Recursion detected in acquisition wrapper` if an object
with a `__parent__` pointer points to a wrapper that in turn points to the
original object.

- Prevent wrappers to be created while accessing `__parent__` on types derived
from Explicit or Implicit base classes.

Expand Down
10 changes: 9 additions & 1 deletion src/Acquisition/_Acquisition.c
Expand Up @@ -545,7 +545,15 @@ Wrapper_findattr(Wrapper *self, PyObject *oname,
Py_XDECREF(r); Py_XDECREF(v); Py_XDECREF(tb);
r=NULL;
}
/* normal attribute lookup */
/* Deal with mixed __parent__ / aq_parent circles */
else if (self->container && isWrapper(self->container) &&
WRAPPER(self->container)->container &&
self == WRAPPER(WRAPPER(self->container)->container)) {
PyErr_SetString(PyExc_RuntimeError,
"Recursion detected in acquisition wrapper");
return NULL;
}
/* normal attribute lookup */
else if ((r=PyObject_GetAttr(self->obj,oname)))
{
if (r==Acquired)
Expand Down
9 changes: 3 additions & 6 deletions src/Acquisition/tests.py
Expand Up @@ -2362,7 +2362,7 @@ def test___parent__aq_parent_circles():
>>> x.__parent__.__parent__ is x
True
>>> x.hello
'world'
>>> Acquisition.aq_acquire(x, 'hello')
Expand All @@ -2383,20 +2383,17 @@ def test___parent__aq_parent_circles():
>>> Acquisition.aq_acquire(y, 'non_existant_attr')
Traceback (most recent call last):
...
AttributeError: non_existant_attr
RuntimeError: Recursion detected in acquisition wrapper
>>> x.non_existant_attr
Traceback (most recent call last):
...
AttributeError: non_existant_attr
"""
# XXX: disabled
"""
>>> y.non_existant_attr
Traceback (most recent call last):
...
AttributeError: non_existant_attr
RuntimeError: Recursion detected in acquisition wrapper
"""

def test_unwrapped_implicit_acquirer_unwraps__parent__():
Expand Down

0 comments on commit 5a6a6f4

Please sign in to comment.