From 510feccd3181847ecde2342e7b966c3363f7502f Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:12:34 +0100 Subject: [PATCH] core: add `None` check to a device's `extra_description` (cherry-pick #11904) (#11906) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit core: add `None` check to a device's `extra_description` (#11904) Co-authored-by: Simonyi Gergő <28359278+gergosimonyi@users.noreply.github.com> --- authentik/core/api/devices.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/authentik/core/api/devices.py b/authentik/core/api/devices.py index 58040df8358f..cc8f77f5585b 100644 --- a/authentik/core/api/devices.py +++ b/authentik/core/api/devices.py @@ -1,5 +1,6 @@ """Authenticator Devices API Views""" +from django.utils.translation import gettext_lazy as _ from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import OpenApiParameter, extend_schema from rest_framework.fields import ( @@ -40,7 +41,11 @@ def get_type(self, instance: Device) -> str: def get_extra_description(self, instance: Device) -> str: """Get extra description""" if isinstance(instance, WebAuthnDevice): - return instance.device_type.description + return ( + instance.device_type.description + if instance.device_type + else _("Extra description not available") + ) if isinstance(instance, EndpointDevice): return instance.data.get("deviceSignals", {}).get("deviceModel") return ""