1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #3927: Fix exception when deleting devices with secrets assigned

This commit is contained in:
Jeremy Stretch
2020-01-15 10:39:23 -05:00
parent 1ea820a50e
commit dda9a2ee1c
2 changed files with 8 additions and 2 deletions

View File

@ -8,6 +8,7 @@
* [#3900](https://github.com/netbox-community/netbox/issues/3900) - Fix exception when deleting device types
* [#3914](https://github.com/netbox-community/netbox/issues/3914) - Fix interface filter field when unauthenticated
* [#3927](https://github.com/netbox-community/netbox/issues/3927) - Fix exception when deleting devices with secrets assigned
---

View File

@ -14,6 +14,7 @@ from django.urls import reverse
from django.utils.encoding import force_bytes
from taggit.managers import TaggableManager
from dcim.models import Device
from extras.models import CustomFieldModel, TaggedItem
from utilities.models import ChangeLoggedModel
from .exceptions import InvalidKey
@ -359,10 +360,14 @@ class Secret(ChangeLoggedModel, CustomFieldModel):
super().__init__(*args, **kwargs)
def __str__(self):
if self.role and self.device and self.name:
try:
device = self.device
except Device.DoesNotExist:
device = None
if self.role and device and self.name:
return '{} for {} ({})'.format(self.role, self.device, self.name)
# Return role and device if no name is set
if self.role and self.device:
if self.role and device:
return '{} for {}'.format(self.role, self.device)
return 'Secret'