Skip to content

Commit 57fdfa8

Browse files
bctiemannjeremystretch
authored andcommitted
Fixes: #18263 - Iterate through a freshly queried set of CableTerminations to find endpoints in update_connected_endpoints (#18264)
* Iterate through a freshly queried set of CableTerminations to find endpoints in update_connected_endpoints * Add defensive break if q_filter has not been populated
1 parent 23a3c0b commit 57fdfa8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: netbox/dcim/models/cables.py

+4
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ def from_origin(cls, terminations):
607607
cable_end = 'A' if lct.cable_end == 'B' else 'B'
608608
q_filter |= Q(cable=lct.cable, cable_end=cable_end)
609609

610+
# Make sure this filter has been populated; if not, we have probably been given invalid data
611+
if not q_filter:
612+
break
613+
610614
remote_cable_terminations = CableTermination.objects.filter(q_filter)
611615
remote_terminations = [ct.termination for ct in remote_cable_terminations]
612616
else:

Diff for: netbox/dcim/signals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs):
8585
if instance._terminations_modified:
8686
a_terminations = []
8787
b_terminations = []
88-
for t in instance.terminations.all():
88+
# Note: instance.terminations.all() is not safe to use here as it might be stale
89+
for t in CableTermination.objects.filter(cable=instance):
8990
if t.cable_end == CableEndChoices.SIDE_A:
9091
a_terminations.append(t.termination)
9192
else:

0 commit comments

Comments
 (0)