Skip to content

CLI script invocation is broken in NetBox 4.3.1 #19529

@peteeckel

Description

@peteeckel

Deployment Type

Self-hosted

NetBox Version

v4.3.1

Python Version

3.11

Steps to Reproduce

  1. Set SCRIPTS_ROOT = '/opt/netbox/netbox/scripts' in configuration.py
  2. Create a custom script and save it as dummy.py:
from extras.scripts import Script

name = "Dummy"


class Dummy(Script):

    class Meta:
        name = "Dummy Script"
        commit_default = True

    def run(self, data, commit):
        self.log_info(f"Script was executed")
  1. Add the script to NetBox using "Customization/Scripts/Add"
  2. Try to run the script using the GUI
  3. Verify that the script gets executed properly
Image 6. Now try to run the script using the API:
# /opt/netbox/netbox/manage.py runscript dummy.Dummy

Expected Behavior

The script gets executed from the command line, like in NetBox 4.2.9:

# /opt/netbox/netbox/manage.py runscript dummy.Dummy
[2025-05-18 09:40:21,967][INFO] - Running script (commit=False)
[2025-05-18 09:40:21,967][INFO] - Script was executed
[2025-05-18 09:40:21,968][INFO] - Database changes have been reverted automatically.
[2025-05-18 09:40:21,973][INFO] - Script completed in 0 minutes, 0.01 seconds

Observed Behavior

Script execution failed with an exception:

# /opt/netbox/netbox/manage.py runscript dummy.Dummy
Traceback (most recent call last):
  File "/opt/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 41, in handle
    script_obj = get_module_and_script(module_name, script_name)[1]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/scripts.py", line 649, in get_module_and_script
    module = ScriptModule.objects.get(file_path=f'{module_name}.py')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 633, in get
    raise self.model.DoesNotExist(
extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist.

The script can be made to run in NetBox 4.3.1 with a modified invocation (which is definitely not how it's supposed to work):

# /opt/netbox/netbox/manage.py runscript /opt/netbox/netbox/scripts/dummy.Dummy
[2025-05-18 09:36:02,840][INFO] - Running script (commit=False)
[2025-05-18 09:36:02,840][INFO] - Script was executed
[2025-05-18 09:36:02,840][INFO] - Database changes have been reverted automatically.
[2025-05-18 09:36:02,847][INFO] - Script completed in 0 minutes, 0.01 seconds

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions