From 91b5f6d79960a8fbaa30affc24a8d553a5dfb093 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 7 Aug 2018 17:30:26 -0400 Subject: [PATCH 01/16] Fixes #2323: DoesNotExist raised when deleting devices or virtual machines --- netbox/dcim/models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index ca18cbb25..564e6fa74 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -7,7 +7,7 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericRelation from django.contrib.postgres.fields import ArrayField, JSONField -from django.core.exceptions import ValidationError +from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.db.models import Count, Q, ObjectDoesNotExist @@ -1933,11 +1933,20 @@ class Interface(ComponentModel): """ Include the connected Interface (if any). """ + + # It's possible that an Interface can be deleted _after_ its parent Device/VM, in which case trying to resolve + # the component parent will raise DoesNotExist. For more discussion, see + # https://github.com/digitalocean/netbox/issues/2323 + try: + parent_obj = self.get_component_parent() + except ObjectDoesNotExist: + parent_obj = None + ObjectChange( user=user, request_id=request_id, changed_object=self, - related_object=self.get_component_parent(), + related_object=parent_obj, action=action, object_data=serialize_object(self, extra={ 'connected_interface': self.connected_interface.pk if self.connection else None, From cfab9a6a0a69e9d53403b25715235c45cb3793d0 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 8 Aug 2018 08:49:23 -0400 Subject: [PATCH 02/16] Fixes #2330: Incorrect tab link in VRF changelog view --- netbox/templates/ipam/vrf.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/templates/ipam/vrf.html b/netbox/templates/ipam/vrf.html index f75b8c7d1..a69ccd0f5 100644 --- a/netbox/templates/ipam/vrf.html +++ b/netbox/templates/ipam/vrf.html @@ -40,7 +40,7 @@ {% include 'inc/created_updated.html' with obj=vrf %}