Skip to content

Commit

Permalink
Handle condition gracefully where an empty object list is passed in t…
Browse files Browse the repository at this point in the history
…o draw_far_objects (e.g. orphaned cable where attached device has been deleted)
  • Loading branch information
bctiemann committed Dec 17, 2024
1 parent 0b9ead3 commit 2c2815e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions netbox/dcim/svg/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c2815e

Please sign in to comment.