Unhelpful message with custom script errors - AttributeError:'NoneType' object has no attribute 'full_name' #9327

Closed
opened 2025-12-29 20:48:32 +01:00 by adam · 0 comments
Owner

Originally created by @candlerb on GitHub (Mar 6, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.3

Python Version

3.8

Steps to Reproduce

  1. Create a local file called wombat.py

    from extras.scripts import Script
    
    class Possum(Script):
        def run(self, data, commit):
            pass
    
  2. Upload this as a custom script via the web UI

  3. Test at CLI: /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum

  4. Edit the file /opt/netbox/netbox/scripts/wombat.py on the Netbox server. Change "def" to "defz" (a gross syntax error)

  5. 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 line import 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'

References

Relates to discussion #15352 and issue #12766

Originally created by @candlerb on GitHub (Mar 6, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.3 ### Python Version 3.8 ### Steps to Reproduce 1. Create a local file called `wombat.py` ``` from extras.scripts import Script class Possum(Script): def run(self, data, commit): pass ``` 2. Upload this as a custom script via the web UI 3. Test at CLI: `/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript wombat.Possum` 4. Edit the file `/opt/netbox/netbox/scripts/wombat.py` on the Netbox server. Change "def" to "defz" (a gross syntax error) 5. 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 line `import 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'` ### References Relates to discussion #15352 and issue #12766
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 20:48:32 +01:00
adam closed this issue 2025-12-29 20:48:32 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9327