Script ordering is nondeterministic for Managed File #9557

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

Originally created by @jchambers2012 on GitHub (Apr 29, 2024).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.76

Feature type

Change to existing functionality

Proposed functionality

Today it appears that the “/extras/scripts/” view is sorted based on core_managedfile’s data_synced field. I would like to see the order_by be defined or want to add a new setting to the configuration to allow for us to set a static way for the screen to render.
Hardcode this line 4b21cf604b/netbox/extras/views.py (L1220) to

        script_modules = ScriptModule.objects.restrict(request.user).order_by("data_path")

Or allow for a config setting like below:

        script_modules = ScriptModule.objects.restrict(request.user)
        ORDERING_CHOICES = ["data_path","file_path"]
        sort = getattr(settings,"SCRIPT_VIEW_SORT",None)
        if sort in ORDERING_CHOICES:
            script_modules = script_modules.order_by(sort_field)
        return render(request, 'extras/script_list.html', {

Hardcoding the .order_by("data_path") fixes the issue on my local box no matter how files are added or updated to the script page

Use case

Our end users complain that the script groups jump all over the page as we add or update script in Netbox. This forces them to have to scroll up and down the page till they are able to find the group of script they wish to run

Database changes

This is a GUI change and no database changes are expected

External dependencies

n/a

Originally created by @jchambers2012 on GitHub (Apr 29, 2024). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.76 ### Feature type Change to existing functionality ### Proposed functionality Today it appears that the “/extras/scripts/” view is sorted based on core_managedfile’s data_synced field. I would like to see the order_by be defined or want to add a new setting to the configuration to allow for us to set a static way for the screen to render. Hardcode this line https://github.com/netbox-community/netbox/blob/4b21cf604b351f029b398b7811e38cb103b148e0/netbox/extras/views.py#L1220 to ```python script_modules = ScriptModule.objects.restrict(request.user).order_by("data_path") ``` Or allow for a config setting like below: ```python script_modules = ScriptModule.objects.restrict(request.user) ORDERING_CHOICES = ["data_path","file_path"] sort = getattr(settings,"SCRIPT_VIEW_SORT",None) if sort in ORDERING_CHOICES: script_modules = script_modules.order_by(sort_field) return render(request, 'extras/script_list.html', { ``` Hardcoding the `.order_by("data_path")` fixes the issue on my local box no matter how files are added or updated to the script page ### Use case Our end users complain that the script groups jump all over the page as we add or update script in Netbox. This forces them to have to scroll up and down the page till they are able to find the group of script they wish to run ### Database changes This is a GUI change and no database changes are expected ### External dependencies n/a
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:18:56 +01:00
adam closed this issue 2025-12-29 21:18:56 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 29, 2024):

Today it appears that the “/extras/scripts/” view is sorted based on core_managedfile’s data_synced field

Script modules are sorted by their file_root and file_path values (per the parent ManagedFile class). When these are null (because the module is loaded from a remote DataFile), ordering will be nondeterministic as described, which should be considered a bug IMO.

The best approach is probably to tweak the default ordering for ManagedFile to account for the data source & data file fields introduced from SyncedDataMixin.

@jeremystretch commented on GitHub (Apr 29, 2024): > Today it appears that the “/extras/scripts/” view is sorted based on core_managedfile’s data_synced field Script modules are sorted by their `file_root` and `file_path` values (per the parent ManagedFile class). When these are null (because the module is loaded from a remote DataFile), ordering will be nondeterministic as described, which should be considered a bug IMO. The best approach is probably to tweak the default ordering for ManagedFile to account for the data source & data file fields introduced from SyncedDataMixin.
Author
Owner

@jeremystretch commented on GitHub (May 1, 2024):

I was mistaken above; file_root and file_path are defined for all file regardless of origin, however the ScriptModule's Meta class is not inheriting the default ordering defined on ManagedFile.

@jeremystretch commented on GitHub (May 1, 2024): I was mistaken above; `file_root` and `file_path` are defined for all file regardless of origin, however the ScriptModule's Meta class is not inheriting the default ordering defined on ManagedFile.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9557