Custom Script CLI and API execution not working #10433

Closed
opened 2025-12-29 21:31:23 +01:00 by adam · 7 comments
Owner

Originally created by @wz4 on GitHub (Nov 4, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.6

Python Version

3.11

Steps to Reproduce

Unable to execute custom scripts via the CLI and API. This is the same issue referenced in #17885. The fix implemented only applies to the GUI.

Adding the script name as an argument to the enqueue method fixes the problem.

27d15615b3/netbox/extras/api/views.py (L281-L290)

27d15615b3/netbox/extras/management/commands/runscript.py (L84-L100)

Expected Behavior

Executing a script for the CLI and API should work

Observed Behavior

The following error is produced when attempting to use the CLI runscript command

  File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 85, in handle
    job = ScriptJob.enqueue(
          ^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/jobs.py", line 106, in enqueue
    return Job.enqueue(cls.handle, name=name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/core/models/jobs.py", line 236, in enqueue
    job.full_clean()
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1561, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'name': ['This field cannot be blank.']}
Originally created by @wz4 on GitHub (Nov 4, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### Triage priority N/A ### NetBox Version v4.1.6 ### Python Version 3.11 ### Steps to Reproduce Unable to execute custom scripts via the CLI and API. This is the same issue referenced in #17885. The fix implemented only applies to the GUI. Adding the script name as an argument to the enqueue method fixes the problem. https://github.com/netbox-community/netbox/blob/27d15615b3590000901984bddfa7a815cd1343d8/netbox/extras/api/views.py#L281-L290 https://github.com/netbox-community/netbox/blob/27d15615b3590000901984bddfa7a815cd1343d8/netbox/extras/management/commands/runscript.py#L84-L100 ### Expected Behavior Executing a script for the CLI and API should work ### Observed Behavior The following error is produced when attempting to use the CLI runscript command ``` File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 85, in handle job = ScriptJob.enqueue( ^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/netbox/jobs.py", line 106, in enqueue return Job.enqueue(cls.handle, name=name, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/core/models/jobs.py", line 236, in enqueue job.full_clean() File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1561, in full_clean raise ValidationError(errors) django.core.exceptions.ValidationError: {'name': ['This field cannot be blank.']} ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:31:23 +01:00
adam closed this issue 2025-12-29 21:31:23 +01:00
Author
Owner

@cruse1977 commented on GitHub (Nov 4, 2024):

+1 to this

@cruse1977 commented on GitHub (Nov 4, 2024): +1 to this
Author
Owner

@alehaa commented on GitHub (Nov 4, 2024):

I repeat my comment from #17885 and volunteer for submitting a PR:

The bug originates from the following code. The justification of this was to not have the script name twice (as job name and related object) listed in the job table. Just having "SciptJob" as generic name seemed a bit odd to me at that time. 58bc388457/netbox/extras/jobs.py (L24-L27)
[…] Reverting #17886 and removing the code linked above should fix the issue and avoid confusion. ScriptJob will be used as default name afterwards and the script linked as job object.

@alehaa commented on GitHub (Nov 4, 2024): I repeat my comment from #17885 and volunteer for submitting a PR: > The bug originates from the following code. The justification of this was to not have the script name twice (as job name and related object) listed in the job table. Just having "SciptJob" as generic name seemed a bit odd to me at that time. https://github.com/netbox-community/netbox/blob/58bc3884578a98595b02d7d7412c83d41fc7bbfa/netbox/extras/jobs.py#L24-L27 > […] Reverting #17886 and removing the code linked above should fix the issue and avoid confusion. `ScriptJob` will be used as default name afterwards and the script linked as job object.
Author
Owner

@arthanson commented on GitHub (Nov 4, 2024):

@alehaa do you want to submit a PR, can you also check if it addresses #17921?

@arthanson commented on GitHub (Nov 4, 2024): @alehaa do you want to submit a PR, can you also check if it addresses #17921?
Author
Owner

@llamafilm commented on GitHub (Nov 10, 2024):

@alehaa are you still planning on making a PR?

@llamafilm commented on GitHub (Nov 10, 2024): @alehaa are you still planning on making a PR?
Author
Owner

@alehaa commented on GitHub (Nov 10, 2024):

There is already one linked to this issue. :)

@alehaa commented on GitHub (Nov 10, 2024): There is already one linked to this issue. :)
Author
Owner

@llamafilm commented on GitHub (Nov 10, 2024):

Thanks! I missed that. I tested your change now and I can confirm it fixes the problem for both CLI and scheduled script execution.

@llamafilm commented on GitHub (Nov 10, 2024): Thanks! I missed that. I tested your change now and I can confirm it fixes the problem for both CLI and scheduled script execution.
Author
Owner

@jeremystretch commented on GitHub (Nov 21, 2024):

I believe this has been resolved by PR #17932.

@jeremystretch commented on GitHub (Nov 21, 2024): I believe this has been resolved by PR #17932.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10433