add slight workaround

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-12-18 00:31:13 +01:00
parent 4a1332290f
commit adcfb3092e
No known key found for this signature in database
1 changed files with 13 additions and 5 deletions

View File

@ -204,14 +204,22 @@ class MobileTransaction(ExpiringModel):
def wait_for_response(self, max_checks=30) -> TransactionStates: def wait_for_response(self, max_checks=30) -> TransactionStates:
"""Wait for a change in status""" """Wait for a change in status"""
checks = 0 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: while True:
self.refresh_from_db() try:
if self.status in [TransactionStates.ACCEPT, TransactionStates.DENY]: obj.refresh_from_db()
self.delete() except MobileTransaction.DoesNotExist:
return self.status return TransactionStates.DENY
if obj.status in [TransactionStates.ACCEPT, TransactionStates.DENY]:
obj.delete()
return obj.status
checks += 1 checks += 1
if checks > max_checks: if checks > max_checks:
self.delete() obj.delete()
raise TimeoutError() raise TimeoutError()
sleep(1) sleep(1)