policies: improve error handling when using bindings without policy

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-16 11:04:31 +02:00
parent ebf9f0ca63
commit 17503365f7
1 changed files with 4 additions and 4 deletions

View File

@ -81,11 +81,11 @@ class PolicyEngine:
.iterator()
)
def _check_policy_type(self, policy: Policy):
def _check_policy_type(self, binding: PolicyBinding):
"""Check policy type, make sure it's not the root class as that has no logic implemented"""
# pyright: reportGeneralTypeIssues=false
if policy.__class__ == Policy:
raise TypeError(f"Policy '{policy}' is root type")
if binding.policy is not None and binding.policy.__class__ == Policy:
raise TypeError(f"Policy '{binding.policy}' is root type")
def build(self) -> "PolicyEngine":
"""Build wrapper which monitors performance"""
@ -102,7 +102,7 @@ class PolicyEngine:
for binding in self._iter_bindings():
self.__expected_result_count += 1
self._check_policy_type(binding.policy)
self._check_policy_type(binding)
key = cache_key(binding, self.request)
cached_policy = cache.get(key, None)
if cached_policy and self.use_cache: