Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
candlerb opened this issue Mar 6, 2024 · 0 comments · Fixed by #15441
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@candlerb
Copy link
Contributor

candlerb commented Mar 6, 2024

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

@candlerb candlerb added the type: bug A confirmed report of unexpected behavior in the application label Mar 6, 2024
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available labels Mar 8, 2024
@arthanson arthanson self-assigned this Mar 14, 2024
@arthanson arthanson removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Mar 14, 2024
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Apr 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants