From 51a79505fe10b0599b47eacced2f31622dbc9606 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Mon, 20 Jan 2025 22:21:36 -0600 Subject: [PATCH 1/2] Fixes: #18433 - Fix missing is_primary property on MACAddress model --- netbox/dcim/models/devices.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index dbcd91ea0ed..49fd46d237e 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -1522,3 +1522,10 @@ class Meta: def __str__(self): return str(self.mac_address) + + @property + def is_primary(self): + if self.assigned_object and hasattr(self.assigned_object, 'primary_mac_address'): + if self.assigned_object.primary_mac_address and self.assigned_object.primary_mac_address.pk == self.pk: + return True + return False From 32196092536abc6c8141ad5c3aa974f14922674a Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Thu, 23 Jan 2025 18:30:54 -0600 Subject: [PATCH 2/2] Change to `@cached_property` --- netbox/dcim/models/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 49fd46d237e..87a87c90b45 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -1523,7 +1523,7 @@ class Meta: def __str__(self): return str(self.mac_address) - @property + @cached_property def is_primary(self): if self.assigned_object and hasattr(self.assigned_object, 'primary_mac_address'): if self.assigned_object.primary_mac_address and self.assigned_object.primary_mac_address.pk == self.pk: