diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 745a146f2..f6c791819 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -596,8 +596,7 @@ class CablePath(models.Model): if cable not in cables: cables.append(cable) path.append(cables) - print(len(path), max_length) - if len(path) > max_length: + if len(path) >= max_length: logger.warning('Infinite loop detected while updating cable path trace') break diff --git a/netbox/dcim/tests/test_cablepaths.py b/netbox/dcim/tests/test_cablepaths.py index d04bfb80d..d4b9daae6 100644 --- a/netbox/dcim/tests/test_cablepaths.py +++ b/netbox/dcim/tests/test_cablepaths.py @@ -6,6 +6,7 @@ from dcim.choices import LinkStatusChoices from dcim.models import * from dcim.svg import CableTraceSVG from dcim.utils import object_to_path_node +from dcim.choices import CableEndChoices class CablePathTestCase(TestCase): @@ -2380,5 +2381,15 @@ class CablePathTestCase(TestCase): CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id) CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id) - cable_1._terminations_modified = True - cable_1.save() + cable_1.save(max_length=50) + a_terminations = [] + b_terminations = [] + for t in cable_1.terminations.all(): + if t.cable_end == CableEndChoices.SIDE_A: + a_terminations.append(t.termination) + else: + b_terminations.append(t.termination) + cp = CablePath.from_origin(a_terminations, max_length=50) + self.assertEqual(len(cp.path), 50) + cp = CablePath.from_origin(b_terminations, max_length=10) + self.assertEqual(len(cp.path), 3)