From 7d6d7942d91ab7e7060e60c016bc49dbeb735ed9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 2 Dec 2016 16:09:07 -0500 Subject: [PATCH] Rewrote get_connected_interface() to return first connection if more than one exist (erroneously) --- netbox/dcim/models.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 93cdb95d5..01b373376 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -1173,16 +1173,13 @@ class Interface(models.Model): return None def get_connected_interface(self): - try: - connection = InterfaceConnection.objects.select_related().get(Q(interface_a=self) | Q(interface_b=self)) - if connection.interface_a == self: - return connection.interface_b - else: - return connection.interface_a - except InterfaceConnection.DoesNotExist: - return None - except InterfaceConnection.MultipleObjectsReturned: - raise MultipleObjectsReturned("Multiple connections found for {} interface {}!".format(self.device, self)) + connection = InterfaceConnection.objects.select_related().filter(Q(interface_a=self) | Q(interface_b=self))\ + .first() + if connection and connection.interface_a == self: + return connection.interface_b + elif connection: + return connection.interface_a + return None class InterfaceConnection(models.Model):