Misleading error message printed when using manage.py runscript #10333

Closed
opened 2025-12-29 21:30:09 +01:00 by adam · 3 comments
Owner

Originally created by @iraduica on GitHub (Oct 8, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.12

Steps to Reproduce

This was happening because I was trying to import a python lib that wasn't installed.

Expected Behavior

In the UI there should be some kind of error message, not just the removal of "Run Script" button, also in the error message printed by the CLI version, at least the name of the script should be mentioned.

Observed Behavior

In GUI there is no error message, only "Run Script" button was removed, while in CLI the error message displayed is:

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.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.12/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.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 41, in handle
    module, script_obj = get_module_and_script(module_name, script_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/scripts.py", line 604, in get_module_and_script
    script = module.scripts.get(name=script_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 649, in get
    raise self.model.DoesNotExist(
extras.models.scripts.Script.DoesNotExist: Script matching query does not exist.
Originally created by @iraduica on GitHub (Oct 8, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.1.1 ### Python Version 3.12 ### Steps to Reproduce This was happening because I was trying to import a python lib that wasn't installed. ### Expected Behavior In the UI there should be some kind of error message, not just the removal of "Run Script" button, also in the error message printed by the CLI version, at least the name of the script should be mentioned. ### Observed Behavior In GUI there is no error message, only "Run Script" button was removed, while in CLI the error message displayed is: ``` 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.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.12/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.12/site-packages/django/core/management/base.py", line 413, in run_from_argv self.execute(*args, **cmd_options) File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 41, in handle module, script_obj = get_module_and_script(module_name, script_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/extras/scripts.py", line 604, in get_module_and_script script = module.scripts.get(name=script_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 649, in get raise self.model.DoesNotExist( extras.models.scripts.Script.DoesNotExist: Script matching query does not exist. ```
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:30:09 +01:00
adam closed this issue 2025-12-29 21:30:10 +01:00
Author
Owner

@arthanson commented on GitHub (Oct 9, 2024):

@iii-arch I'm getting a different error message, can you please provide a simple sample script to make sure this is the same issue.

@arthanson commented on GitHub (Oct 9, 2024): @iii-arch I'm getting a different error message, can you please provide a simple sample script to make sure this is the same issue.
Author
Owner

@iraduica commented on GitHub (Oct 10, 2024):

Sure, here is the sample:

from netaddr import IPNetwork

from extras.scripts import Script
from ipam.models import IPAddress
from objexplore import explore

name = "Test Script"

class Test(Script):
    class Meta:
        name="Test"
        description="Test Script"
    def run(self, data, commit):
        address = IPAddress(
            address = IPNetwork("10.1.1.1/24")
        )
        address.save()
@iraduica commented on GitHub (Oct 10, 2024): Sure, here is the sample: ``` from netaddr import IPNetwork from extras.scripts import Script from ipam.models import IPAddress from objexplore import explore name = "Test Script" class Test(Script): class Meta: name="Test" description="Test Script" def run(self, data, commit): address = IPAddress( address = IPNetwork("10.1.1.1/24") ) address.save() ```
Author
Owner

@github-actions[bot] commented on GitHub (Oct 18, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Oct 18, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10333