Scripts run on command line fail with extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist. #11234

Closed
opened 2025-12-29 21:42:18 +01:00 by adam · 2 comments
Owner

Originally created by @pobk on GitHub (May 29, 2025).

Deployment Type

NetBox Cloud

NetBox Version

4.3.1

Python Version

3.12

Steps to Reproduce

  1. Add a new script
  2. Using ./manage.py runscript scriptfile.ScriptModuleThing try to run the script

Expected Behavior

The script is expected to be run as per normal.

Observed Behavior

Raises a extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist.

Originally created by @pobk on GitHub (May 29, 2025). ### Deployment Type NetBox Cloud ### NetBox Version 4.3.1 ### Python Version 3.12 ### Steps to Reproduce 1. Add a new script 2. Using `./manage.py runscript scriptfile.ScriptModuleThing` try to run the script ### Expected Behavior The script is expected to be run as per normal. ### Observed Behavior Raises a extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist.
adam added the type: bugstatus: duplicate labels 2025-12-29 21:42:18 +01:00
adam closed this issue 2025-12-29 21:42:18 +01:00
Author
Owner

@pobk commented on GitHub (May 29, 2025):

The problem seems to be in extras/management/commands/runscript.py where the command is passing the the incomplete path to the get_module_and_script function... or the function get_module_and_script in is not properly filtering for the full path in the database:

(venv) ubuntu@netbox-5b85bc6b9f-lll92:/opt/netbox/netbox$ ./manage.py shell
{...snip...}
>>> from extras.scripts import ScriptModule
>>> allscripts = ScriptModule.objects.all()
>>> allscripts
<RestrictedQuerySet [<ScriptModule: createcircuit>]>
>>> allscripts[0]
<ScriptModule: createcircuit>
>>> allscripts[0].file_path
'/opt/netbox/netbox/scripts/testscript.py'
>>> 

Whereas get_module_and_script only has the module name available:

def get_module_and_script(module_name, script_name):
    module = ScriptModule.objects.get(file_path=f'{module_name}.py')
    script = module.scripts.get(name=script_name)
    return module, script
@pobk commented on GitHub (May 29, 2025): The problem seems to be in [extras/management/commands/runscript.py](https://github.com/netbox-community/netbox/blob/main/netbox/extras/management/commands/runscript.py) where the command is passing the the incomplete path to the `get_module_and_script` function... or the function [`get_module_and_script`](https://github.com/netbox-community/netbox/blob/main/netbox/extras/scripts.py#L648) in is not properly filtering for the full path in the database: ``` (venv) ubuntu@netbox-5b85bc6b9f-lll92:/opt/netbox/netbox$ ./manage.py shell {...snip...} >>> from extras.scripts import ScriptModule >>> allscripts = ScriptModule.objects.all() >>> allscripts <RestrictedQuerySet [<ScriptModule: createcircuit>]> >>> allscripts[0] <ScriptModule: createcircuit> >>> allscripts[0].file_path '/opt/netbox/netbox/scripts/testscript.py' >>> ``` Whereas `get_module_and_script` only has the module name available: ``` def get_module_and_script(module_name, script_name): module = ScriptModule.objects.get(file_path=f'{module_name}.py') script = module.scripts.get(name=script_name) return module, script ```
Author
Owner

@arthanson commented on GitHub (May 29, 2025):

dupe of #19529

@arthanson commented on GitHub (May 29, 2025): dupe of #19529
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11234