Skip to content

Custom Script CLI and API execution not working #17923

@wz4

Description

@wz4

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.

ScriptJob.enqueue(
instance=script,
user=request.user,
data=input_serializer.data['data'],
request=copy_safe_request(request),
commit=input_serializer.data['commit'],
job_timeout=script.python_class.job_timeout,
schedule_at=input_serializer.validated_data.get('schedule_at'),
interval=input_serializer.validated_data.get('interval')
)

# Execute the script.
job = ScriptJob.enqueue(
instance=script_obj,
user=user,
immediate=True,
data=data,
request=NetBoxFakeRequest({
'META': {},
'POST': data,
'GET': {},
'FILES': {},
'user': user,
'path': '',
'id': uuid.uuid4()
}),
commit=commit,
)

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.']}

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions