From 7ff679b1a3243feb6c13500b030820a870731473 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 14 Jan 2021 16:52:22 +0100 Subject: [PATCH] policies: fix error when error occurs during policy process with no target --- authentik/policies/engine.py | 6 ++++-- authentik/policies/models.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/authentik/policies/engine.py b/authentik/policies/engine.py index a1c83bb83..92acd0d6a 100644 --- a/authentik/policies/engine.py +++ b/authentik/policies/engine.py @@ -82,8 +82,10 @@ class PolicyEngine: def _iter_bindings(self) -> Iterator[PolicyBinding]: """Make sure all Policies are their respective classes""" - return PolicyBinding.objects.filter(target=self.__pbm, enabled=True).order_by( - "order" + return ( + PolicyBinding.objects.filter(target=self.__pbm, enabled=True) + .order_by("order") + .iterator() ) def _check_policy_type(self, policy: Policy): diff --git a/authentik/policies/models.py b/authentik/policies/models.py index df9783d7d..f5ca6ff7c 100644 --- a/authentik/policies/models.py +++ b/authentik/policies/models.py @@ -64,7 +64,10 @@ class PolicyBinding(SerializerModel): return PolicyBindingSerializer def __str__(self) -> str: - return f"Policy Binding {self.target} #{self.order} {self.policy}" + try: + return f"Policy Binding {self.target} #{self.order} {self.policy}" + except PolicyBinding.target.RelatedObjectDoesNotExist: # pylint: disable=no-member + return f"Policy Binding - #{self.order} {self.policy}" class Meta: