From 4739f27c149a9c9a800fb8dc5f7914dcc5fd7663 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 29 May 2025 13:52:00 -0700 Subject: [PATCH 1/3] #15390 add trace signal if cable terminatiions changed --- netbox/dcim/models/cables.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 0a28d5acb..73a7f1357 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -220,6 +220,7 @@ class Cable(PrimaryModel): b_terminations = {ct.termination: ct for ct in self.terminations.filter(cable_end='B')} # Delete stale CableTerminations + if self._terminations_modified: for termination, ct in a_terminations.items(): if termination.pk and termination not in self.a_terminations: @@ -312,6 +313,12 @@ class CableTermination(ChangeLoggedModel): def __str__(self): return f'Cable {self.cable} to {self.termination}' + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self._orig_cable = self.__dict__.get('cable') + self._orig_cable_end = self.__dict__.get('cable_end') + def clean(self): super().clean() @@ -349,6 +356,7 @@ class CableTermination(ChangeLoggedModel): # Cache objects associated with the terminating object (for filtering) self.cache_related_objects() + created = self.pk is None super().save(*args, **kwargs) @@ -359,6 +367,29 @@ class CableTermination(ChangeLoggedModel): termination.cable_end = self.cable_end termination.save() + # figure out which cable terminations changed + update_cable_termination = False + update_orig_cable_termination = False + if created: + update_cable_termination = True + else: + if self._orig_cable and self._orig_cable != self.cable: + update_cable_termination = True + update_orig_cable_termination = True + elif self._orig_cable_end and self._orig_cable_end != self.cable_end: + update_cable_termination = True + + if update_cable_termination: + self.cable._terminations_modified = True + trace_paths.send(Cable, instance=self.cable, created=False) + + if update_orig_cable_termination: + self._orig_cable._terminations_modified = True + trace_paths.send(Cable, instance=self._orig_cable, created=False) + + self._orig_cable_end = self.cable_end + self._orig_cable = self.cable + def delete(self, *args, **kwargs): # Delete the cable association on the terminating object @@ -369,6 +400,7 @@ class CableTermination(ChangeLoggedModel): termination.save() super().delete(*args, **kwargs) + trace_paths.send(Cable, instance=self.cable, created=False) def cache_related_objects(self): """ From e8891f770ced790c7195f1844cdad4367c3a276d Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 29 May 2025 14:39:41 -0700 Subject: [PATCH 2/3] #15390 add trace signal if cable terminatiions changed --- netbox/dcim/models/cables.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 73a7f1357..7608302c9 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -370,9 +370,7 @@ class CableTermination(ChangeLoggedModel): # figure out which cable terminations changed update_cable_termination = False update_orig_cable_termination = False - if created: - update_cable_termination = True - else: + if not created: if self._orig_cable and self._orig_cable != self.cable: update_cable_termination = True update_orig_cable_termination = True From 5fb81e9943a85cb7b905d6e2897a3a135fcde1dc Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 29 May 2025 15:14:31 -0700 Subject: [PATCH 3/3] #15390 add trace signal if cable terminatiions changed --- netbox/dcim/models/cables.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 7608302c9..b2b14a87f 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -368,22 +368,23 @@ class CableTermination(ChangeLoggedModel): termination.save() # figure out which cable terminations changed - update_cable_termination = False - update_orig_cable_termination = False if not created: + update_cable_termination = False + update_orig_cable_termination = False + if self._orig_cable and self._orig_cable != self.cable: update_cable_termination = True update_orig_cable_termination = True elif self._orig_cable_end and self._orig_cable_end != self.cable_end: update_cable_termination = True - if update_cable_termination: - self.cable._terminations_modified = True - trace_paths.send(Cable, instance=self.cable, created=False) + if update_cable_termination: + self.cable._terminations_modified = True + trace_paths.send(Cable, instance=self.cable, created=False) - if update_orig_cable_termination: - self._orig_cable._terminations_modified = True - trace_paths.send(Cable, instance=self._orig_cable, created=False) + if update_orig_cable_termination: + self._orig_cable._terminations_modified = True + trace_paths.send(Cable, instance=self._orig_cable, created=False) self._orig_cable_end = self.cable_end self._orig_cable = self.cable