Scripts: can't import modules relative to script file #16698
Labels
severity: low
Does not significantly disrupt application functionality, or a workaround is available
status: needs owner
This issue is tentatively accepted pending a volunteer committed to its implementation
type: bug
A confirmed report of unexpected behavior in the application
Deployment Type
Self-hosted
NetBox Version
v4.0.3
Python Version
3.11
Steps to Reproduce
SCRIPT_ROOT
to a directory outside Netbox's root_common.py
which contains a classImporter
(see this file for example)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:
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.
settings.py
addsys.path.append(SCRIPTS_ROOT)
but there is probably a risk of name collision between Netbox modules and scripts ?BASE_DIR
(like the default/scripts
. Here depending on Netbox deployment process, it might get wiped at each upgrade (like in our case).from scripts._common import Importer
as imports work from Netbox's root directory).Let me know if I can be of any help.
Thanks
The text was updated successfully, but these errors were encountered: