Add UI URL pattern for scripts to allow a specific script to be accessed by module and class in addition to ID #10480

Closed
opened 2025-12-29 21:32:05 +01:00 by adam · 3 comments
Owner

Originally created by @atownson on GitHub (Nov 15, 2024).

Originally assigned to: @atownson on GitHub.

NetBox version

v4.1.6

Feature type

New functionality

Triage priority

I volunteer to perform this work (if approved)

Proposed functionality

Related to #16145, proposing to allow a URL pattern for scripts to reference them by <module>.<class>. The scope of this request is simply to allow this new URL pattern in addition to the existing scripts/<int:pk>/, scripts/<int:pk>/source/, and scripts/<int:pk>/jobs/ patterns. The templates and Script.get_absolute_url() would still reference the pk. The suggested URL pattern should match the allowed pattern for the API resolved in #16145.

Use case

When using Custom Links to link to a specific script, using the pk is problematic because it's subject to change as the scripts are updated over time. By allowing the <module>.<class> pattern, the custom links could be configured to use that pattern and return the correct script.

Database changes

None

External dependencies

None

Originally created by @atownson on GitHub (Nov 15, 2024). Originally assigned to: @atownson on GitHub. ### NetBox version v4.1.6 ### Feature type New functionality ### Triage priority I volunteer to perform this work (if approved) ### Proposed functionality Related to #16145, proposing to allow a URL pattern for scripts to reference them by `<module>.<class>`. The scope of this request is simply to allow this new URL pattern in addition to the existing `scripts/<int:pk>/`, `scripts/<int:pk>/source/`, and `scripts/<int:pk>/jobs/` patterns. The templates and `Script.get_absolute_url()` would still reference the pk. The suggested URL pattern should match the allowed pattern for the API resolved in #16145. ### Use case When using Custom Links to link to a specific script, using the pk is problematic because it's subject to change as the scripts are updated over time. By allowing the `<module>.<class>` pattern, the custom links could be configured to use that pattern and return the correct script. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:32:05 +01:00
adam closed this issue 2025-12-29 21:32:05 +01:00
Author
Owner

@ross-cello commented on GitHub (Feb 19, 2025):

Ah excellent, have just come across the same issue when evaluating an upgrade from v3.7.8.

Seems it might be a capability regression introduced in v4.0.0.

For us, it breaks navigation on dependent Custom Links, Export Templates and Custom Scripts where URLs are constructed.

I have only just started digging, but comparing the /netbox/extras/urls.py seems to start there.

v4.2.3 (current) /netbox/extras/urls.py [ From Line 74 ]
...
    # Scripts
    path('scripts/', views.ScriptListView.as_view(), name='script_list'),
    path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'),
    path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'),
    path('scripts/<int:pk>/', views.ScriptView.as_view(), name='script'),
    path('scripts/<int:pk>/source/', views.ScriptSourceView.as_view(), name='script_source'),
    path('scripts/<int:pk>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'),
    path('script-modules/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))),
...
v3.7.8 /netbox/extras/urls.py [ From Line 128 ]
...
    # Scripts
    path('scripts/', views.ScriptListView.as_view(), name='script_list'),
    path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'),
    path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'),
    path('scripts/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))),
    path('scripts/<str:module>/<str:name>/', views.ScriptView.as_view(), name='script'), <----- missing
    path('scripts/<str:module>/<str:name>/source/', views.ScriptSourceView.as_view(), name='script_source'), <----- missing
    path('scripts/<str:module>/<str:name>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'), <----- missing
...

IIRC, the URL path also changed between v2 and v3, from scripts/module.name/ to scripts/module/name/.
We had similar breakages at that point as well, but the URL path was still human readable.

@ross-cello commented on GitHub (Feb 19, 2025): Ah excellent, have just come across the same issue when evaluating an upgrade from v3.7.8. Seems it might be a capability regression introduced in v4.0.0. For us, it breaks navigation on dependent Custom Links, Export Templates and Custom Scripts where URLs are constructed. I have only just started digging, but comparing the `/netbox/extras/urls.py` seems to start there. ##### v4.2.3 (current) [/netbox/extras/urls.py](https://github.com/netbox-community/netbox/blob/v4.2.3/netbox/extras/urls.py) [ [From Line 74](https://github.com/netbox-community/netbox/blob/260adfc9e79d870cb6bbdd05c594c470ba066d93/netbox/extras/urls.py#L74) ] ``` ... # Scripts path('scripts/', views.ScriptListView.as_view(), name='script_list'), path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'), path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'), path('scripts/<int:pk>/', views.ScriptView.as_view(), name='script'), path('scripts/<int:pk>/source/', views.ScriptSourceView.as_view(), name='script_source'), path('scripts/<int:pk>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'), path('script-modules/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))), ... ``` ##### v3.7.8 [/netbox/extras/urls.py](https://github.com/netbox-community/netbox/blob/v3.7.8/netbox/extras/urls.py) [ [From Line 128](https://github.com/netbox-community/netbox/blob/be903a64a2f5e2b6d070ac40adbff13197656242/netbox/extras/urls.py#L128) ] ``` ... # Scripts path('scripts/', views.ScriptListView.as_view(), name='script_list'), path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'), path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'), path('scripts/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))), path('scripts/<str:module>/<str:name>/', views.ScriptView.as_view(), name='script'), <----- missing path('scripts/<str:module>/<str:name>/source/', views.ScriptSourceView.as_view(), name='script_source'), <----- missing path('scripts/<str:module>/<str:name>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'), <----- missing ... ``` IIRC, the URL path also changed between v2 and v3, from `scripts/module.name/` to `scripts/module/name/`. We had similar breakages at that point as well, but the URL path was still human readable.
Author
Owner

@rrizun commented on GitHub (Feb 24, 2025):

I encountered this exact issue when evaluating an upgrade from 3.7.8 to 4 .. would be great to get the /scripts/module/name url back again!

@rrizun commented on GitHub (Feb 24, 2025): I encountered this exact issue when evaluating an upgrade from 3.7.8 to 4 .. would be great to get the /scripts/module/name url back again!
Author
Owner

@atownson commented on GitHub (Feb 24, 2025):

I can work on this.

@atownson commented on GitHub (Feb 24, 2025): I can work on this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10480