You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Align behavior with objects raising in __getattr__ (#157)
* tests: test C and PYTHON implementations in testPermissionRole
* Align behavior with objects raising in `__getattr__`
The observed problem was a behavior different between C and python
implementation on python 3, happening with Zope python script. When the
context can not be accessed by the current user, Zope binds a
`Shared.DC.Scripts.Bindings.UnauthorizedBinding`, a class that raises an
Unauthorized error when the context is actually accessed, in order to
postpone the Unauthorized if something is actually accessed. This class
does implements this by raising Unauthorized in `__getattr__`.
The python implementation of `rolesForPermissionOn` used `hasattr` and
`hasattr` has changed between python2 and python3, on python2 it was
ignoring all exceptions, including potential Unauthorized errors and
just returning False, but on python3 these errors are now raised.
This change of behavior of python causes `rolesForPermissionOn` to
behave differently: when using python implementation on python2 or when
using C implementation, such Unauthorized errors were gracefully handled
and caused `checkPermission` to return False, but on python3 the
Unauthorized is raised.
The C implementation of `rolesForPermissionOn` uses a construct
equivalent to the python2 version of `hasattr`. For consistency - and
because ignoring errors is usually not good - we also want to change it
to be have like the python3 implementation.
This change make this scenario behave the same between python and C
implementations:
- `Unauthorized` errors raised in `__getattr__` are supported on py3.
- Other errors than `AttributeError` and `Unauthorized` raised in
`__getattr__` are no longer ignored in the C implementation.
Co-authored-by: Dieter Maurer <[email protected]>
Copy file name to clipboardexpand all lines: CHANGES.rst
+2
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ For changes before version 3.0, see ``HISTORY.rst``.
8
8
9
9
- Respect ``PURE_PYTHON`` environment variable set to ``0`` when running tests.
10
10
11
+
- Let the roles access in ``rolesForPermissionOn`` interpret ``AttributeError`` and ``Unauthorized`` as "no roles definition for this permission at this object" and report any other exception (for the Python and C implementation). We have to treat ``Unauthorized`` like ``AttributeError`` to support ``Shared.DC.Scripts.Bindings.UnauthorizedBinding`` which raises ``Unauthorized`` for any access.
0 commit comments