From f7b85ab9411667fc7b9b429f680476bbbcde2698 Mon Sep 17 00:00:00 2001 From: kkthxbye-code Date: Mon, 19 Dec 2022 08:59:21 +0100 Subject: [PATCH] Return no terminations if the cable is unsaved --- netbox/dcim/models/cables.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 406231ef5..6fd99d18a 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -112,6 +112,10 @@ class Cable(PrimaryModel): def a_terminations(self): if hasattr(self, '_a_terminations'): return self._a_terminations + + if not self.pk: + return [] + # Query self.terminations.all() to leverage cached results return [ ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_A @@ -127,6 +131,10 @@ class Cable(PrimaryModel): def b_terminations(self): if hasattr(self, '_b_terminations'): return self._b_terminations + + if not self.pk: + return [] + # Query self.terminations.all() to leverage cached results return [ ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_B