Update media view to preserve the exception.

This commit is contained in:
Daniel Sheppard 2025-08-11 13:00:43 -05:00
parent 1cb10eeb4f
commit 244e738ebb

View File

@ -6,7 +6,6 @@ from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse from django.urls import reverse
from django.urls.exceptions import NoReverseMatch from django.urls.exceptions import NoReverseMatch
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from rest_framework.exceptions import AuthenticationFailed
from netbox.api.authentication import TokenAuthentication from netbox.api.authentication import TokenAuthentication
from netbox.plugins import PluginConfig from netbox.plugins import PluginConfig
@ -47,12 +46,9 @@ class TokenConditionalLoginRequiredMixin(ConditionalLoginRequiredMixin):
# Attempt to authenticate the user using a DRF token, if provided # Attempt to authenticate the user using a DRF token, if provided
if settings.LOGIN_REQUIRED and not request.user.is_authenticated: if settings.LOGIN_REQUIRED and not request.user.is_authenticated:
authenticator = TokenAuthentication() authenticator = TokenAuthentication()
try: auth_info = authenticator.authenticate(request)
auth_info = authenticator.authenticate(request) if auth_info is not None:
if auth_info is not None: request.user = auth_info[0] # User object
request.user = auth_info[0] # User object
except AuthenticationFailed:
pass
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)