From 65dcf305794feffb1da33c15b5af8d4964580d72 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 19 Nov 2008 02:21:37 +0000 Subject: - Fix ModelGraphTraverser; don't try to change the ``__name__`` or ``__parent__`` of an object that claims it implements ILocation during traversal even if the ``__name__`` or ``__parent__`` of the object traversed does not match the name used in the traversal step or the or the traversal parent . Rationale: it was insane to do so. This bug was only found due to a misconfiguration in an application that mistakenly had intermediate persistent non-ILocation objects; traversal was causing a persistent write on every request under this setup. - ``repoze.bfg.location.locate`` now unconditionally sets ``__name__`` and ``__parent__`` on objects which provide ILocation (it previously only set them conditionally if they didn't match attributes already present on the object via equality). Prep for 0.5.0. --- repoze/bfg/location.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'repoze/bfg/location.py') diff --git a/repoze/bfg/location.py b/repoze/bfg/location.py index 11f08faf9..ed7d2ad1f 100644 --- a/repoze/bfg/location.py +++ b/repoze/bfg/location.py @@ -39,10 +39,10 @@ def inside(model1, model2): def locate(model, parent, name=None): """ If ``model`` explicitly provides the - ``repoze.bfg.interfaces.ILocation`` interface, locate ``model`` - directly set ``model`` 's ``__parent__`` attribute to the - ``parent`` object (also a model), and its ``__name__`` to the - supplied ``name`` argument. + ``repoze.bfg.interfaces.ILocation`` interface, directly set + ``model`` 's ``__parent__`` attribute to the ``parent`` object + (also a model), and its ``__name__`` to the supplied ``name`` + argument, and return the model. If ``model`` does *not* explicitly provide the ``repoze.bfg.interfaces.ILocation`` interface, return a @@ -53,8 +53,8 @@ def locate(model, parent, name=None): instances. """ if ILocation.providedBy(model): - if parent is not model.__parent__ or name != model.__name__: - _locate(model, parent, name) + model.__parent__ = parent + model.__name__ = name return model return LocationProxy(model, parent, name) @@ -83,10 +83,6 @@ def lineage(model): yield model model = getattr(model, '__parent__', None) -def _locate(model, parent, name=None): - model.__parent__ = parent - model.__name__ = name - class ClassAndInstanceDescr(object): def __init__(self, *args): -- cgit v1.2.3