Fix lookup error on invalid URLs

closes #119
This commit is contained in:
Tobias Kunze 2025-06-26 13:39:43 +02:00
parent 1c69c634cc
commit b29ef95c89

View file

@ -20,6 +20,10 @@ class OrganizationMiddleware:
organization_slug = url.kwargs.get("organization")
if organization_slug:
pk = organization_slug.rsplit("-", maxsplit=1)[-1]
try:
pk = int(pk)
except ValueError:
pk = -1
request.organization = get_object_or_404(Organization, pk=pk)
with scope(organization=request.organization):
return self.get_response(request)