diff --git a/netbox/dcim/models/device_component_templates.py b/netbox/dcim/models/device_component_templates.py index 20f99ecb2..6ff58b0f0 100644 --- a/netbox/dcim/models/device_component_templates.py +++ b/netbox/dcim/models/device_component_templates.py @@ -122,7 +122,9 @@ class ModularComponentTemplateModel(ComponentTemplateModel): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.__original_device_type = self.device_type_id + + # Cache the original DeviceType ID for reference under clean() + self._original_device_type = self.device_type_id def to_objectchange(self, action): objectchange = super().to_objectchange(action) @@ -135,9 +137,9 @@ class ModularComponentTemplateModel(ComponentTemplateModel): def clean(self): super().clean() - if self.pk is not None and self.__original_device_type != self.device_type_id: + if self.pk is not None and self._original_device_type != self.device_type_id: raise ValidationError({ - "device": "device_type field is read-only and not updatable." + "device_type": "Component templates cannot be moved to a different device type." }) # A component template must belong to a DeviceType *or* to a ModuleType diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index 5b0442dff..c30ce3a97 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -80,7 +80,9 @@ class ComponentModel(NetBoxModel): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.__original_device = self.device_id + + # Cache the original Device ID for reference under clean() + self._original_device = self.device_id def __str__(self): if self.label: @@ -95,9 +97,9 @@ class ComponentModel(NetBoxModel): def clean(self): super().clean() - if self.pk is not None and self.__original_device != self.device_id: + if self.pk is not None and self._original_device != self.device_id: raise ValidationError({ - "device": "Device field is read-only and not updatable." + "device": "Components cannot be moved to a different device." }) @property