Custom field objects sort by ID rather than what they display #7149

Closed
opened 2025-12-29 20:19:44 +01:00 by adam · 3 comments
Owner

Originally created by @neuro42 on GitHub (Oct 21, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.6

Python version

3.9

Steps to Reproduce

  1. Add a custom field
    1. Model: IPAM > prefix
    2. Name: gateway
    3. Type: object
    4. Object type: IPAM > IP address
  2. Add some IP addresses (being out of sorted order)
    1. 172.16.42.1/24
    2. 172.16.10.1/24
    3. 172.16.128.1/24
    4. 172.16.6.1/24
  3. Add some prefixes, using the added IP address objects for the custom gateway field
    1. 172.16.42.0/24 w/ 172.16.42.1/24
    2. 172.16.10.0/24 w/ 172.16.10.1/24
    3. 172.16.128.0/24 w/ 172.16.128.1/24
    4. 172.16.6.0/24 w/ 172.16.6.1/24
  4. View the prefix list, and configure the table to include the custom gateway field
  5. click on the gateway column header to sort by the custom field

Expected Behavior

Gateway column to be in sorted IP address order:
172.16.6.1/24
172.16.10.1/24
172.16.42.1/24
172.16.128.1/24

Observed Behavior

Gateway column is sorted by object id (creation order):
172.16.42.1/24
172.16.10.1/24
172.16.128.1/24
172.16.6.1/24

Non-custom columns (eg: site) are sorted by their name, and not their ID

Originally created by @neuro42 on GitHub (Oct 21, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.6 ### Python version 3.9 ### Steps to Reproduce 1. Add a custom field 1. Model: IPAM > prefix 2. Name: gateway 3. Type: object 4. Object type: IPAM > IP address 2. Add some IP addresses (being out of sorted order) 1. 172.16.42.1/24 2. 172.16.10.1/24 3. 172.16.128.1/24 4. 172.16.6.1/24 3. Add some prefixes, using the added IP address objects for the custom gateway field 1. 172.16.42.0/24 w/ 172.16.42.1/24 2. 172.16.10.0/24 w/ 172.16.10.1/24 3. 172.16.128.0/24 w/ 172.16.128.1/24 4. 172.16.6.0/24 w/ 172.16.6.1/24 4. View the prefix list, and configure the table to include the custom gateway field 5. click on the gateway column header to sort by the custom field ### Expected Behavior Gateway column to be in sorted IP address order: 172.16.6.1/24 172.16.10.1/24 172.16.42.1/24 172.16.128.1/24 ### Observed Behavior Gateway column is sorted by object id (creation order): 172.16.42.1/24 172.16.10.1/24 172.16.128.1/24 172.16.6.1/24 Non-custom columns (eg: site) are sorted by their name, and not their ID
adam added the type: bugstatus: accepted labels 2025-12-29 20:19:44 +01:00
adam closed this issue 2025-12-29 20:19:44 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2022):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Oct 25, 2022): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@neuro42 commented on GitHub (Oct 29, 2022):

Steps to reproduce rewritten

@neuro42 commented on GitHub (Oct 29, 2022): Steps to reproduce rewritten
Author
Owner

@arthanson commented on GitHub (Nov 9, 2022):

Unfortunately, this isn't really easily supportable with the way custom-fields are implemented. The issue here is that for object-type custom fields the ID of the object is stored so it is basically a generic-foreign-key, so the sorting is happening on the ID (which would be the creation order). It would not be straight-forward to de-reference this to the object and sort on the appropriate sub-field in a performant way for the list. After discussion we will probably look at disabling sorting on this if the custom-field is an object or multi-object type.

@arthanson commented on GitHub (Nov 9, 2022): Unfortunately, this isn't really easily supportable with the way custom-fields are implemented. The issue here is that for object-type custom fields the ID of the object is stored so it is basically a generic-foreign-key, so the sorting is happening on the ID (which would be the creation order). It would not be straight-forward to de-reference this to the object and sort on the appropriate sub-field in a performant way for the list. After discussion we will probably look at disabling sorting on this if the custom-field is an object or multi-object type.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7149