Skip to content

Commit

Permalink
root: handle asgi exception (goauthentik#10085)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu authored Jun 12, 2024
1 parent 05cfbca commit 113d6cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions authentik/core/api/used_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def get_delete_action(manager: Manager) -> str:
"""Get the delete action from the Foreign key, falls back to cascade"""
if hasattr(manager, "field"):
if manager.field.remote_field.on_delete.__name__ == SET_NULL.__name__:
return DeleteAction.SET_NULL.name
return DeleteAction.SET_NULL.value
if manager.field.remote_field.on_delete.__name__ == SET_DEFAULT.__name__:
return DeleteAction.SET_DEFAULT.name
return DeleteAction.SET_DEFAULT.value
if hasattr(manager, "source_field"):
return DeleteAction.CASCADE_MANY.name
return DeleteAction.CASCADE.name
return DeleteAction.CASCADE_MANY.value
return DeleteAction.CASCADE.value


class UsedByMixin:
Expand Down
2 changes: 1 addition & 1 deletion authentik/crypto/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_used_by(self):
"model_name": "oauth2provider",
"pk": str(provider.pk),
"name": str(provider),
"action": DeleteAction.SET_NULL.name,
"action": DeleteAction.SET_NULL.value,
}
],
)
Expand Down
7 changes: 6 additions & 1 deletion authentik/root/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from time import perf_counter, time
from typing import Any

from channels.exceptions import DenyConnection
from django.conf import settings
from django.contrib.sessions.backends.base import UpdateError
from django.contrib.sessions.exceptions import SessionInterrupted
Expand Down Expand Up @@ -271,7 +272,11 @@ def __init__(self, inner):

async def __call__(self, scope, receive, send):
self.log(scope)
return await self.inner(scope, receive, send)
try:
return await self.inner(scope, receive, send)
except Exception as exc:
LOGGER.warning("Exception in ASGI application", exc=exc)
raise DenyConnection() from None

def log(self, scope: dict, **kwargs):
"""Log request"""
Expand Down

0 comments on commit 113d6cc

Please sign in to comment.