diff --git a/CHANGELOG.md b/CHANGELOG.md
index 864fbb35a..d27ed0ff2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -45,6 +45,7 @@ NetBox now supports modeling physical cables for console, power, and interface c
* [#2622](https://github.com/digitalocean/netbox/issues/2622) - Enable filtering cables by multiple types/colors
* [#2624](https://github.com/digitalocean/netbox/issues/2624) - Delete associated content type and permissions when removing InterfaceConnection model
* [#2616](https://github.com/digitalocean/netbox/issues/2616) - Convert Rack `outer_unit` and Cable `length_unit` to integer-based choice fields
+* [#2639](https://github.com/digitalocean/netbox/issues/2639) - Fix preservation of length/dimensions unit for racks and cables
## API Changes
diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py
index 8f85f280e..379460f84 100644
--- a/netbox/dcim/models.py
+++ b/netbox/dcim/models.py
@@ -554,7 +554,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
# Validate outer dimensions and unit
if (self.outer_width is not None or self.outer_depth is not None) and self.outer_unit is None:
raise ValidationError("Must specify a unit when setting an outer width/depth")
- else:
+ elif self.outer_width is None and self.outer_depth is None:
self.outer_unit = None
if self.pk:
@@ -2586,7 +2586,7 @@ class Cable(ChangeLoggedModel):
# Validate length and length_unit
if self.length is not None and self.length_unit is None:
raise ValidationError("Must specify a unit when setting a cable length")
- else:
+ elif self.length is None:
self.length_unit = None
def save(self, *args, **kwargs):
diff --git a/netbox/templates/dcim/cable_trace.html b/netbox/templates/dcim/cable_trace.html
index 17cfd2025..fc645e644 100644
--- a/netbox/templates/dcim/cable_trace.html
+++ b/netbox/templates/dcim/cable_trace.html
@@ -31,7 +31,7 @@
{{ cable.get_status_display }}
{{ cable.get_type_display|default:"" }}
- {% if cable.length %}- {{ cable.length }}{{ cable.length_unit }}{% endif %}
+ {% if cable.length %}- {{ cable.length }}{{ cable.get_length_unit_display }}{% endif %}
{% else %}