mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-01 15:13:27 +02:00
fix(dcim): Handle missing Virtual Circuit Termination gracefully
Replace direct attribute access with try-except to catch ObjectDoesNotExist when virtual_circuit_termination relation is missing. Prevents errors when rendering Virtual Circuits Panel with broken or missing terminations. Fixes #21808
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -532,8 +533,14 @@ class VirtualCircuitPanel(panels.ObjectPanel):
|
||||
|
||||
def render(self, context):
|
||||
obj = context.get('object')
|
||||
if not obj or not obj.is_virtual or not obj.virtual_circuit_termination:
|
||||
if not obj or not obj.is_virtual:
|
||||
return ''
|
||||
|
||||
try:
|
||||
obj.virtual_circuit_termination
|
||||
except ObjectDoesNotExist:
|
||||
return ''
|
||||
|
||||
ctx = self.get_context(context)
|
||||
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user