I'm having an issue that is kind of worrying me. I have an app almost only working with traversal.
In order to get my admin paths, I have a node that gets attached to the root. on __getitem__
, it returns parent.__getitem__
which is my actual root. With containment
on my views. I can check that this admin node is contained.
The problem happens when rerooting. When I do that
class AdminRoot(object):
__acl__ = [
(Allow, 'g:admin', ALL_PERMISSIONS),
(Deny, 'system.Everyone', ALL_PERMISSIONS),
]
def __init__(self, parent, name):
self.__parent__ = parent
self.__name__ = name
def __getitem__(self, name):
item = Mapping.__getitem__(self.__parent__, name)
item.__parent__ = self
return item
When self
is affected to item.__parent__
. It get sometimes saved as the parent node. For that reason, when doing request.resource_url
. It will either output from the admin root or the real root.
I wish that this affectation was never saved at all.
Whenever you set an attribute on a Persistent
object, it get's saved to the ZODB (provided no exception triggered a transaction abort).
In the ZODB, objects really should have only one parent, and thus only one, canonical URL. It is not recommended that you try and make such objects appear to have multiple URLs, at least not by manipulating the __parent__
attribute.
Rather, you should provide a __resource_url__()
method to provide alternative URLs instead. You can use volatile attributes to store non-persistent information on your objects for such a method to use, perhaps.
Volatile attributes are any attribute starting with _v_
and are ignored by the persistence engine.