Not possible to use custom scripts in nested packages #6932

Closed
opened 2025-12-29 19:46:56 +01:00 by adam · 1 comment
Owner

Originally created by @kkthxbye-code on GitHub (Sep 5, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.3.2

Python version

3.10

Steps to Reproduce

Create the following folder structure:

./scripts/__init__.py
./scripts/testscript.py
./scripts/subscriptfolder/__init__.py 
./scripts/subscriptfolder/myscript1.py
./scripts/subscriptfolder/myscript2.py

testscript.py contains script class TestScript(Script):

myscript1.py contains script class MyScript1(Script):

myscript2.py contains script class MyScript2(Script):

__init__.py contains:

from myscript1 import MyScript1
from myscript2 import MyScript2

Expected Behavior

Three scripts should be shown on the script page:

TestScript under the testscript heading and MyScript1 and MyScript2 under the subscriptfolder heading.

All scripts should work as expected.

Observed Behavior

All scripts show in the list as expected, but clicking on the subscriptsfolder scripts will cause a 404 error as the URL points to subscriptsfolder.myscript1.MyScript1 but the returned dict from get_scripts() is in the following format:

{
  "subscriptsfolder": {"MyScript1": MyScript1() }
}

Noticably missing the myscript1 part of the module path.

This makes it hard to organize scripts as there is no way to get scripts under the same heading without having them in the same file.

Originally created by @kkthxbye-code on GitHub (Sep 5, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.3.2 ### Python version 3.10 ### Steps to Reproduce Create the following folder structure: ``` ./scripts/__init__.py ./scripts/testscript.py ./scripts/subscriptfolder/__init__.py ./scripts/subscriptfolder/myscript1.py ./scripts/subscriptfolder/myscript2.py ``` `testscript.py` contains script `class TestScript(Script):` `myscript1.py` contains script `class MyScript1(Script):` `myscript2.py` contains script `class MyScript2(Script):` `__init__.py` contains: ``` from myscript1 import MyScript1 from myscript2 import MyScript2 ``` ### Expected Behavior Three scripts should be shown on the script page: TestScript under the testscript heading and MyScript1 and MyScript2 under the subscriptfolder heading. All scripts should work as expected. ### Observed Behavior All scripts show in the list as expected, but clicking on the subscriptsfolder scripts will cause a 404 error as the URL points to subscriptsfolder.myscript1.MyScript1 but the returned dict from `get_scripts()` is in the following format: ``` { "subscriptsfolder": {"MyScript1": MyScript1() } } ``` Noticably missing the `myscript1` part of the module path. This makes it hard to organize scripts as there is no way to get scripts under the same heading without having them in the same file.
adam added the type: bugstatus: accepted labels 2025-12-29 19:46:56 +01:00
adam closed this issue 2025-12-29 19:46:56 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Sep 5, 2022):

I'll provide a PR for this. I have a working PoC just need to polish it up. There should be no backward incompatible changes. Let me know if you have any worries, otherwise I'll seek feedback on the PR.

Also, I wasn't sure if this should have been a FR or not. I decided on bug as the scripts show up in the script list but doesn't work.

@kkthxbye-code commented on GitHub (Sep 5, 2022): I'll provide a PR for this. I have a working PoC just need to polish it up. There should be no backward incompatible changes. Let me know if you have any worries, otherwise I'll seek feedback on the PR. Also, I wasn't sure if this should have been a FR or not. I decided on bug as the scripts show up in the script list but doesn't work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6932