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
This commit is contained in:
bctiemann 2025-01-06 09:54:13 -05:00 committed by GitHub
parent 40f22533d1
commit c9ee699633
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -607,6 +607,10 @@ class CablePath(models.Model):
cable_end = 'A' if lct.cable_end == 'B' else 'B' cable_end = 'A' if lct.cable_end == 'B' else 'B'
q_filter |= Q(cable=lct.cable, cable_end=cable_end) 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_cable_terminations = CableTermination.objects.filter(q_filter)
remote_terminations = [ct.termination for ct in remote_cable_terminations] remote_terminations = [ct.termination for ct in remote_cable_terminations]
else: else:

View File

@ -85,7 +85,8 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs):
if instance._terminations_modified: if instance._terminations_modified:
a_terminations = [] a_terminations = []
b_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: if t.cable_end == CableEndChoices.SIDE_A:
a_terminations.append(t.termination) a_terminations.append(t.termination)
else: else: