policies: fix error when error occurs during policy process with no target

This commit is contained in:
Jens Langhammer 2021-01-14 16:52:22 +01:00
parent 8beddcddb0
commit 7ff679b1a3
2 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -64,7 +64,10 @@ class PolicyBinding(SerializerModel):
return PolicyBindingSerializer
def __str__(self) -> str:
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: