"service" does not preserve the order of ports when editing #8871

Closed
opened 2025-12-29 20:42:22 +01:00 by adam · 1 comment
Owner

Originally created by @candlerb on GitHub (Nov 22, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.6.5

Python version

3.8

Steps to Reproduce

  1. Create a "service", and enter the ports as "9093,9095,9998-9999"
  2. View the list of services
  3. Edit the service (i.e. click the pencil icon at the end of the service row)

Expected Behavior

Either the ports to remain in the order originally entered, or to be sorted. (I note that the data type in the underlying Postgres column is integer[] which is an ordered list)

Observed Behavior

When viewing the table of services (/ipam/services/), the ports are shown in order:

image

It also shows the same when viewing the details of an individual service (e.g. /ipam/services/2/)

However, when editing the service (/ipam/services/2/edit/), the ports are in a randomized order:

image

This matches what's in the database, which in the same randomized order:

netbox=# select ports from ipam_service where id=2
         ports
-----------------------
 {9999,9093,9998,9095}
(1 row)
Originally created by @candlerb on GitHub (Nov 22, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.6.5 ### Python version 3.8 ### Steps to Reproduce 1. Create a "service", and enter the ports as "9093,9095,9998-9999" 2. View the list of services 3. Edit the service (i.e. click the pencil icon at the end of the service row) ### Expected Behavior Either the ports to remain in the order originally entered, or to be sorted. (I note that the data type in the underlying Postgres column is `integer[]` which is an ordered list) ### Observed Behavior When viewing the table of services (`/ipam/services/`), the ports are shown in order: <img width="304" alt="image" src="https://github.com/netbox-community/netbox/assets/44789/632b5313-7241-45d3-8649-b16fb9c4b6f0"> It also shows the same when viewing the details of an individual service (e.g. `/ipam/services/2/`) However, when editing the service (`/ipam/services/2/edit/`), the ports are in a randomized order: <img width="681" alt="image" src="https://github.com/netbox-community/netbox/assets/44789/494f89cc-80b5-4b48-a27f-498992c159e3"> This matches what's in the database, which in the same randomized order: ``` netbox=# select ports from ipam_service where id=2 ports ----------------------- {9999,9093,9998,9095} (1 row) ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 20:42:22 +01:00
adam closed this issue 2025-12-29 20:42:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 28, 2023):

This is due to a bug in utilities.forms.utils.parse_numeric_range(). We're calling set() on the expanded value to remove potential duplicates, but not ordering the result after casting it to a list.

@jeremystretch commented on GitHub (Nov 28, 2023): This is due to a bug in `utilities.forms.utils.parse_numeric_range()`. We're calling `set()` on the expanded value to remove potential duplicates, but not ordering the result after casting it to a list.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8871