-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Deployment Type
Self-hosted
NetBox Version
v3.7.3
Python Version
3.8
Steps to Reproduce
-
Create a local file called
wombat.pyfrom extras.scripts import Script class Possum(Script): def run(self, data, commit): pass -
Upload this as a custom script via the web UI
-
Test at CLI:
/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum -
Edit the file
/opt/netbox/netbox/scripts/wombat.pyon the Netbox server. Change "def" to "defz" (a gross syntax error) -
Re-run same CLI command:
/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum
Expected Behavior
A useful error message, such as
File "/opt/netbox/netbox/scripts/wombat.py", line 4
defz run(self, data, commit):
^
SyntaxError: invalid syntax
Observed Behavior
A confusing error message:
# /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum
Traceback (most recent call last):
File "/opt/netbox/netbox/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 95, in handle
logger = logging.getLogger(f"netbox.scripts.{script.full_name}")
AttributeError: 'NoneType' object has no attribute 'full_name'
Additional Reproducers
It's also possible to reproduce this problem without a syntax error:
- After
from extras.scripts import Script, add a lineimport foo from bar. OR: - Change the class name "Possum" to "Dingo"
Then re-run the exact same CLI command: /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum
The errors I'd expect would be along the lines of:
Traceback (most recent call last):
File "/opt/netbox/netbox/scripts/wombat.py", line 2, in <module>
from foo import bar
ModuleNotFoundError: No module named 'foo'
or
AttributeError: module 'wombat' has no attribute 'Possum'
But instead, these both still give AttributeError: 'NoneType' object has no attribute 'full_name'