Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script ordering is nondeterministic for Managed File #15891

Closed
jchambers2012 opened this issue Apr 29, 2024 · 2 comments · Fixed by #15907
Closed

Script ordering is nondeterministic for Managed File #15891

jchambers2012 opened this issue Apr 29, 2024 · 2 comments · Fixed by #15907
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@jchambers2012
Copy link
Contributor

jchambers2012 commented Apr 29, 2024

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

script_modules = ScriptModule.objects.restrict(request.user)
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

@jchambers2012 jchambers2012 added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels Apr 29, 2024
@jchambers2012 jchambers2012 changed the title All for Script to be sorted based on configuration Allow for Script to be sorted based on configuration Apr 29, 2024
@jeremystretch
Copy link
Member

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 jeremystretch removed their assignment Apr 29, 2024
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available type: bug A confirmed report of unexpected behavior in the application and removed type: feature Introduction of new functionality to the application status: needs triage This issue is awaiting triage by a maintainer labels Apr 29, 2024
@jchambers2012 jchambers2012 changed the title Allow for Script to be sorted based on configuration Script are ordering is nondeterministic for Managed File Apr 30, 2024
@jeremystretch jeremystretch changed the title Script are ordering is nondeterministic for Managed File Script ordering is nondeterministic for Managed File May 1, 2024
@jeremystretch
Copy link
Member

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 jeremystretch self-assigned this May 1, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels May 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants