From c9ee699633a05c3ce2e2735b55cad7fb48822ea1 Mon Sep 17 00:00:00 2001 From: bctiemann Date: Mon, 6 Jan 2025 09:54:13 -0500 Subject: [PATCH] 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 --- netbox/dcim/models/cables.py | 4 ++++ netbox/dcim/signals.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 2a4748610..2bdaa50eb 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -607,6 +607,10 @@ class CablePath(models.Model): cable_end = 'A' if lct.cable_end == 'B' else 'B' q_filter |= Q(cable=lct.cable, cable_end=cable_end) + # Make sure this filter has been populated; if not, we have probably been given invalid data + if not q_filter: + break + remote_cable_terminations = CableTermination.objects.filter(q_filter) remote_terminations = [ct.termination for ct in remote_cable_terminations] else: diff --git a/netbox/dcim/signals.py b/netbox/dcim/signals.py index a51872719..6c213d64c 100644 --- a/netbox/dcim/signals.py +++ b/netbox/dcim/signals.py @@ -85,7 +85,8 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs): if instance._terminations_modified: a_terminations = [] b_terminations = [] - for t in instance.terminations.all(): + # Note: instance.terminations.all() is not safe to use here as it might be stale + for t in CableTermination.objects.filter(cable=instance): if t.cable_end == CableEndChoices.SIDE_A: a_terminations.append(t.termination) else: