Skip to content

Commit

Permalink
14033 raise validation error if A and B term go to same object (netbo…
Browse files Browse the repository at this point in the history
…x-community#14050)

* 14033 raise validation error if A and B term go to same object

* 14033 move check to cable model clean

* 14033 fix tests
  • Loading branch information
arthanson authored Nov 1, 2023
1 parent 5b2f294 commit b3fb393
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ def clean(self):
if b_type not in COMPATIBLE_TERMINATION_TYPES.get(a_type):
raise ValidationError(f"Incompatible termination types: {a_type} and {b_type}")

if a_type == b_type:
# can't directly use self.a_terminations here as possible they
# don't have pk yet
a_pks = set(obj.pk for obj in self.a_terminations if obj.pk)
b_pks = set(obj.pk for obj in self.b_terminations if obj.pk)

if (a_pks & b_pks):
raise ValidationError(
_("A and B terminations cannot connect to the same object.")
)

# Run clean() on any new CableTerminations
for termination in self.a_terminations:
CableTermination(cable=self, cable_end='A', termination=termination).clean()
Expand Down

0 comments on commit b3fb393

Please sign in to comment.