From e47eea9bf4920ef87c1c4f775d54f7f5d364f36e Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 12 Dec 2025 09:24:39 -0800 Subject: [PATCH] cleanup --- netbox/dcim/models/devices.py | 3 +-- netbox/dcim/models/modules.py | 3 +-- netbox/dcim/signals.py | 2 -- netbox/dcim/utils.py | 33 --------------------------------- 4 files changed, 2 insertions(+), 39 deletions(-) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 950a0cf31..6c5a2d85d 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -957,8 +957,7 @@ class Device( if cf_defaults := CustomField.objects.get_defaults_for_model(model): for component in components: component.custom_field_data = cf_defaults - # Set denormalized references (_site, _location, _rack) before bulk_create - # since bulk_create bypasses the save() method + # Set denormalized references for component in components: component._site = self.site component._location = self.location diff --git a/netbox/dcim/models/modules.py b/netbox/dcim/models/modules.py index e3934da00..b5071794a 100644 --- a/netbox/dcim/models/modules.py +++ b/netbox/dcim/models/modules.py @@ -315,8 +315,7 @@ class Module(PrimaryModel, ConfigContextModel): for component in create_instances: component.custom_field_data = cf_defaults - # Set denormalized references (_site, _location, _rack) before bulk_create - # since bulk_create bypasses the save() method + # Set denormalized references for component in create_instances: component._site = self.device.site component._location = self.device.location diff --git a/netbox/dcim/signals.py b/netbox/dcim/signals.py index 758cf4821..daff68599 100644 --- a/netbox/dcim/signals.py +++ b/netbox/dcim/signals.py @@ -45,7 +45,6 @@ def handle_location_site_change(instance, created, **kwargs): PowerPanel.objects.filter(location__in=locations).update(site=instance.site) CableTermination.objects.filter(_location__in=locations).update(_site=instance.site) # Update component models for devices in these locations - # (since Device.objects.update() doesn't trigger post_save signals) for model in COMPONENT_MODELS: model.objects.filter(device__location__in=locations).update(_site=instance.site) @@ -58,7 +57,6 @@ def handle_rack_site_change(instance, created, **kwargs): if not created: Device.objects.filter(rack=instance).update(site=instance.site, location=instance.location) # Update component models for devices in this rack - # (since Device.objects.update() doesn't trigger post_save signals) for model in COMPONENT_MODELS: model.objects.filter(device__rack=instance).update( _site=instance.site, diff --git a/netbox/dcim/utils.py b/netbox/dcim/utils.py index e6f7fd98c..a03790ea2 100644 --- a/netbox/dcim/utils.py +++ b/netbox/dcim/utils.py @@ -76,36 +76,3 @@ def update_interface_bridges(device, interface_templates, module=None): ) interface.full_clean() interface.save() - - -def update_device_components(device): - """ - Update denormalized fields (_site, _location, _rack) for all component models - associated with the specified device. - - :param device: Device instance whose components should be updated - """ - from dcim.models import ( - ConsolePort, ConsoleServerPort, DeviceBay, FrontPort, Interface, - InventoryItem, ModuleBay, PowerOutlet, PowerPort, RearPort, - ) - - COMPONENT_MODELS = ( - ConsolePort, - ConsoleServerPort, - DeviceBay, - FrontPort, - Interface, - InventoryItem, - ModuleBay, - PowerOutlet, - PowerPort, - RearPort, - ) - - for model in COMPONENT_MODELS: - model.objects.filter(device=device).update( - _site=device.site, - _location=device.location, - _rack=device.rack, - )