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:
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
* [#3900](https://github.com/netbox-community/netbox/issues/3900) - Fix exception when deleting device types
|
* [#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
|
* [#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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ from django.urls import reverse
|
|||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
|
||||||
|
from dcim.models import Device
|
||||||
from extras.models import CustomFieldModel, TaggedItem
|
from extras.models import CustomFieldModel, TaggedItem
|
||||||
from utilities.models import ChangeLoggedModel
|
from utilities.models import ChangeLoggedModel
|
||||||
from .exceptions import InvalidKey
|
from .exceptions import InvalidKey
|
||||||
@ -359,10 +360,14 @@ class Secret(ChangeLoggedModel, CustomFieldModel):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
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 '{} for {} ({})'.format(self.role, self.device, self.name)
|
||||||
# Return role and device if no name is set
|
# 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 '{} for {}'.format(self.role, self.device)
|
||||||
return 'Secret'
|
return 'Secret'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user