Cable length sorting not working 100% right #5961

Closed
opened 2025-12-29 19:34:56 +01:00 by adam · 1 comment
Owner

Originally created by @PaulR282 on GitHub (Jan 18, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.1.6

Python version

3.8

Steps to Reproduce

(1. Create cables)
2. Go to DCIM/Cables
3. Enable length column
4. Sort by length

Expected Behavior

Cables should be sorted by length

Observed Behavior

image

(the 2cm might be wrong, but should be sorted correctly)

Originally created by @PaulR282 on GitHub (Jan 18, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.1.6 ### Python version 3.8 ### Steps to Reproduce (1. Create cables) 2. Go to DCIM/Cables 3. Enable length column 4. Sort by length ### Expected Behavior Cables should be sorted by length ### Observed Behavior ![image](https://user-images.githubusercontent.com/47193860/149903183-5d44adbd-ae67-4d3c-924e-c4253407ac4d.png) (the 2cm might be wrong, but should be sorted correctly)
adam added the type: bugstatus: accepted labels 2025-12-29 19:34:56 +01:00
adam closed this issue 2025-12-29 19:34:56 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 18, 2022):

I see the issue. It's not in the sorting, but in the calculation of the absolute value which is used for sorting. When declaring lengths as a decimal value, the value is getting rounded as it's being erroneously casted to an integer by the to_meters() function. For example, specifying a length as 0.5 meters will result in an incorrect absolute length, but a length of 50cm will not.

@jeremystretch commented on GitHub (Jan 18, 2022): I see the issue. It's not in the sorting, but in the calculation of the absolute value which is _used_ for sorting. When declaring lengths as a decimal value, the value is getting rounded as it's being erroneously casted to an integer by the `to_meters()` function. For example, specifying a length as 0.5 meters will result in an incorrect absolute length, but a length of 50cm will not.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5961