Skip to content

Data is not passed when using runscript #18800

@krox2

Description

@krox2

Deployment Type

Self-hosted

NetBox Version

v4.2.4

Python Version

3.12

Steps to Reproduce

  1. create a test custom script
$ cat data_source/test.py 
from extras.scripts import Script

class test(Script):

    def run(self, data, commit):
        print(f"data: {data}")
  1. run the custom script and pass data to it using runscript --data ...
$ ./venv/bin/python3 ./netbox/manage.py runscript -v 3 --data '{"site":1}' test.test

I've reverted the change #18612 to fix it locally

--- netbox/extras/management/commands/runscript.py.org  2025-03-04 13:50:41.594946866 +0000
+++ netbox/extras/management/commands/runscript.py      2025-03-04 14:00:21.957497595 +0000
@@ -91,7 +91,8 @@
             instance=script_obj,
             user=user,
             immediate=True,
-            data=form.cleaned_data,
+            #data=form.cleaned_data, this breaks passing data to the script as from.cleaned_data always returns an empty dict, introduced in netbox 4.2.4
+            data=data,
             request=NetBoxFakeRequest({
                 'META': {},
                 'POST': data,

Expected Behavior

$ ./venv/bin/python3 ./netbox/manage.py runscript -v 3 --data '{"site":1}' test.test
[2025-03-04 14:00:35,804][INFO] - Running script (commit=False)
data: {'site': 1}
[2025-03-04 14:00:35,805][INFO] - Database changes have been reverted automatically.
[2025-03-04 14:00:35,811][INFO] - Script completed in 0 minutes, 0.01 seconds

Observed Behavior

$ ./venv/bin/python3 ./netbox/manage.py runscript -v 3 --data '{"site":1}' test.test
[2025-03-04 13:58:59,889][INFO] - Running script (commit=False)
data: {}
[2025-03-04 13:58:59,890][INFO] - Database changes have been reverted automatically.
[2025-03-04 13:58:59,896][INFO] - Script completed in 0 minutes, 0.01 seconds

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugA confirmed report of unexpected behavior in the application

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions