Skip to content

Commit

Permalink
Fixes #10217: Handle exception when trace splits to multiple rear ports
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Aug 31, 2022
1 parent 815b2d8 commit 5ef2d1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 9 additions & 3 deletions netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ def get_split_nodes(self):
"""
Return all available next segments in a split cable path.
"""
rearports = self.path_objects[-1]

return FrontPort.objects.filter(rear_port__in=rearports)
nodes = self.path_objects[-1]

# RearPort splitting to multiple FrontPorts with no stack position
if type(nodes[0]) is RearPort:
return FrontPort.objects.filter(rear_port__in=nodes)
# Cable terminating to multiple FrontPorts mapped to different
# RearPorts connected to different cables
elif type(nodes[0]) is FrontPort:
return RearPort.objects.filter(pk__in=[fp.rear_port_id for fp in nodes])
22 changes: 12 additions & 10 deletions netbox/templates/dcim/cable_trace.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
<h3 class="text-danger">Path split!</h3>
<p>Select a node below to continue:</p>
<ul class="text-start">
{% for next_node in path.get_split_nodes %}
{% if next_node.cable %}
<li>
<a href="{% url 'dcim:frontport_trace' pk=next_node.pk %}">{{ next_node }}</a>
(Cable {{ next_node.cable|linkify }})
</li>
{% else %}
<li class="text-muted">{{ next_node }}</li>
{% endif %}
{% endfor %}
{% for next_node in path.get_split_nodes %}
{% if next_node.cable %}
{% with viewname=next_node|viewname:"trace" %}
<li>
<a href="{% url viewname pk=next_node.pk %}">{{ next_node|meta:"verbose_name"|bettertitle }} {{ next_node }}</a>
(Cable {{ next_node.cable|linkify }})
</li>
{% endwith %}
{% else %}
<li class="text-muted">{{ next_node }}</li>
{% endif %}
{% endfor %}
</ul>
{% else %}
<h3 class="text-center text-success">Trace Completed</h3>
Expand Down

0 comments on commit 5ef2d1d

Please sign in to comment.