Add the functionality to disable sorting of keys in the config contexts (json) #3591

Closed
opened 2025-12-29 18:30:02 +01:00 by adam · 2 comments
Owner

Originally created by @IDunkn0wn on GitHub (Apr 21, 2020).

Environment

  • Python version: 3.7.5
  • NetBox version: 2.7.11

Proposed Functionality

Add the option in configuration.py for example, to disable the sorting of keys in the context data (json format) (whether it been a global or a local context).

Use Case

We are currently automating the deployment of our new DataCenter equipment, so we thought of stocking into Netbox, all of the related static configurations in a json format, which we then dump into a yaml file using ansible and some python scripts, but sadly, since the keys gets sorted out in Netbox, the target file and output differs.

Database Changes

None

External Dependencies

None

Originally created by @IDunkn0wn on GitHub (Apr 21, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7.5 * NetBox version: 2.7.11 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Add the option in configuration.py for example, to disable the sorting of keys in the context data (json format) (whether it been a global or a local context). <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case We are currently automating the deployment of our new DataCenter equipment, so we thought of stocking into Netbox, all of the related static configurations in a json format, which we then dump into a yaml file using ansible and some python scripts, but sadly, since the keys gets sorted out in Netbox, the target file and output differs. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes None <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies None
adam closed this issue 2025-12-29 18:30:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 21, 2020):

This is a function of Python's json library and AFAICT not configurable. For validation purposes, I suggest also sorting the data with which NetBox data is being compared. This ensures that the ordering is always consistent.

@jeremystretch commented on GitHub (Apr 21, 2020): This is a function of Python's `json` library and AFAICT not configurable. For validation purposes, I suggest also sorting the data with which NetBox data is being compared. This ensures that the ordering is always consistent.
Author
Owner

@IDunkn0wn commented on GitHub (Apr 21, 2020):

This is a function of Python's json library and AFAICT not configurable. For validation purposes, I suggest also sorting the data with which NetBox data is being compared. This ensures that the ordering is always consistent.

It is indeed a function of the Json library, I did look into the Netbox code, and found that in the following file, sort_keys was either set to True, or not set at all.

I modified them manually, but after restarting the Netbox service, nothing had changed.

netbox/extras/models.py
netbox/utilities/templatetags/helpers.py
netbox/utilities/forms.py

@IDunkn0wn commented on GitHub (Apr 21, 2020): > This is a function of Python's `json` library and AFAICT not configurable. For validation purposes, I suggest also sorting the data with which NetBox data is being compared. This ensures that the ordering is always consistent. It is indeed a function of the Json library, I did look into the Netbox code, and found that in the following file, sort_keys was either set to True, or not set at all. I modified them manually, but after restarting the Netbox service, nothing had changed. netbox/extras/models.py netbox/utilities/templatetags/helpers.py netbox/utilities/forms.py
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3591