launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #06062
Zope adapter registration and security.py
Hi,
I have been trying to figure out how adapter look-up works in Zope. Please
consider this example:
http://paste.ubuntu.com/546342/
It turns out that the returned adapter depends on the order in which the
interfaces are mentioned in the "implements" statement of "MyImplementation".
QueryAdapter will always return the adapter to the first interface in the
list, in this face "MyAdapterA".
It would be interesting to know if this behavior is intended and deterministic.
This has bearing on our security policy though (which is why I was trying to
figure this out). In my case this translates as follows:
ITarget = IAuthorization
InterfaceA = IHasCustomLanguageCodes
InterfaceB = IProduct
the_name = launchpad.TranslationsAdmin (the named permission)
The IAuthorization objects in security.py get registered as adapters from
"<usedfor>" to IAuthorization, named "<permission>". With the behavior I
identified here, it follows that the selection of the security policy depends
on the order in which the "implement" statement of the "Product" class lists
interfaces. In this case, the Adapter for IHasCustomLangugeCodes shadows the
adapter for IProduct because that list is sorted alphabetically AFAICT.
I was not aware of this. Is everybody else? Is this intended? Is this good?
Henning
Follow ups