-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Description
Deployment Type
Self-hosted
NetBox Version
v4.0.3
Python Version
3.11
Steps to Reproduce
- Set
SCRIPT_ROOTto a directory outside Netbox's root - Create/import a script that is meant to be imported by other scripts, for example
_common.pywhich contains a classImporter(see this file for example) - Create a regular script that imports the above mentioned file/class
from _common import Importer(see this file for example)
Expected Behavior
Hi,
Not sure when that changed, but on 3.2.9, the imported module worked fine, this reduces duplicated code between scripts. That's why I'm opening it as bug report rather than feature request.
Observed Behavior
When opening the script's page, it shows the following error message:
Error loading script.
No module named '_common'
I've been thinking of possible workarounds, I'm obviously not knowledgeable enough on Netbox code, so not sure of all the tradeoff they brings.
- Add the following to the script being executed, tested and works as expected, but probably not optimal
import sys
from os.path import dirname
sys.path.append(dirname(__file__))
from _common import Importer
- In
settings.pyaddsys.path.append(SCRIPTS_ROOT)but there is probably a risk of name collision between Netbox modules and scripts ? - Add the scripts (or at least imported modules) inside Netbox's
BASE_DIR(like the default/scripts. Here depending on Netbox deployment process, it might get wiped at each upgrade (like in our case). - Same as (3), but using a symlink instead, so far my preferred workaround if there is no plans on changing this behavior upstream (and then do the import like
from scripts._common import Importeras imports work from Netbox's root directory).
Let me know if I can be of any help.
Thanks
desnoe and cdanis
Metadata
Metadata
Assignees
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application