From 2c2815e5b8c7d94c39f9183deff9d70a8b47c370 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 16 Dec 2024 19:49:53 -0500 Subject: [PATCH] Handle condition gracefully where an empty object list is passed in to draw_far_objects (e.g. orphaned cable where attached device has been deleted) --- netbox/dcim/svg/cables.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/netbox/dcim/svg/cables.py b/netbox/dcim/svg/cables.py index 4e0f7aea638..0c308c2450e 100644 --- a/netbox/dcim/svg/cables.py +++ b/netbox/dcim/svg/cables.py @@ -268,6 +268,10 @@ def draw_far_objects(self, obj_list, terminations): """ Draw the far-end objects and its terminations and return all created nodes """ + # If an empty list is passed in, return empty results so this cable can be skipped + if len(obj_list) == 0: + return [], [] + # Make sure elements are sorted by name for readability objects = sorted(obj_list, key=lambda x: str(x)) width = self.width / len(objects) @@ -405,6 +409,10 @@ def render(self): near = [term for term in near_terminations if term.object == cable.interface_b] far = [term for term in far_terminations if term.object == cable.interface_a] + # If at this point we have no near or no far terminations, this cable can't be rendered, so skip. + if not (near and far): + continue + # Select most-probable start and end position start = near[0].bottom_center end = far[0].top_center