Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root: handle asgi exception #10085

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"""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

Check warning on line 47 in authentik/core/api/used_by.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/api/used_by.py#L46-L47

Added lines #L46 - L47 were not covered by tests


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
Loading