From adcfb3092e9dd4c19c24b13155b0e9aa90007baa Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 18 Dec 2023 00:31:13 +0100 Subject: [PATCH] add slight workaround Signed-off-by: Jens Langhammer --- .../stages/authenticator_mobile/models.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/authentik/stages/authenticator_mobile/models.py b/authentik/stages/authenticator_mobile/models.py index 5b8a105c1..387023072 100644 --- a/authentik/stages/authenticator_mobile/models.py +++ b/authentik/stages/authenticator_mobile/models.py @@ -204,14 +204,22 @@ class MobileTransaction(ExpiringModel): def wait_for_response(self, max_checks=30) -> TransactionStates: """Wait for a change in status""" checks = 0 + # calling self.refresh_from_db can raise an impossible to catch exception + # (in this case authentik.stages.authenticator_mobile.models.DoesNotExist) + obj = MobileTransaction.objects.filter(pk=self.pk).first() + if not obj: + return TransactionStates.DENY while True: - self.refresh_from_db() - if self.status in [TransactionStates.ACCEPT, TransactionStates.DENY]: - self.delete() - return self.status + try: + obj.refresh_from_db() + except MobileTransaction.DoesNotExist: + return TransactionStates.DENY + if obj.status in [TransactionStates.ACCEPT, TransactionStates.DENY]: + obj.delete() + return obj.status checks += 1 if checks > max_checks: - self.delete() + obj.delete() raise TimeoutError() sleep(1)