RoleMixin.roles_for is a method that returns a new instance of LazyRoleSet on each call. This has exposed an inefficiency with recursive calls in ConditionalRole introduced in #451.
RoleMixin.current_roles meanwhile writes a cache entry to flask.g, without support for cache invalidation, leaving that as a gotcha for the developer.
Both these can be solved by turning roles_for into a non-data descriptor that's stored on the instance and tracks the LazyRoleSet instance for every actor it's been called with. It could also support the Mapping protocol (obj.roles_for[actor]) to make the cache more apparent, although this excludes the (as yet unused) anchors parameter.
Since subclasses may override roles_for, (a) the descriptor may need a new name, or (b) RoleMixin.__init_subclass__ should specifically rewrap the method or (c) raise a depreciation error.
RoleMixin.roles_foris a method that returns a new instance ofLazyRoleSeton each call. This has exposed an inefficiency with recursive calls inConditionalRoleintroduced in #451.RoleMixin.current_rolesmeanwhile writes a cache entry toflask.g, without support for cache invalidation, leaving that as a gotcha for the developer.Both these can be solved by turning
roles_forinto a non-data descriptor that's stored on the instance and tracks theLazyRoleSetinstance for every actor it's been called with. It could also support the Mapping protocol (obj.roles_for[actor]) to make the cache more apparent, although this excludes the (as yet unused) anchors parameter.Since subclasses may override
roles_for, (a) the descriptor may need a new name, or (b)RoleMixin.__init_subclass__should specifically rewrap the method or (c) raise a depreciation error.