Custom Scripts API doesn't pass commit parameter #3428

Closed
opened 2025-12-29 18:29:01 +01:00 by adam · 5 comments
Owner

Originally created by @certanet on GitHub (Feb 29, 2020).

Environment

  • Python version: 3.7.6
  • NetBox version: 2.7.8

Using the REST API to call a custom script is not passing the 'commit' parameter into the run method. Using the GUI form works fine, per #4262, but the missing mandatory parameter fails to run the script via API.

Steps to Reproduce

  1. Use the example custom script from https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/
  2. Send a POST to:
    URI: /api/extras/scripts/new_site.NewBranchScript/
    Body:
    { "data": { "site_name": "123", "switch_count": 2, "switch_model": "Catalyst 3560X-48T" }, "commit": true }

Expected Behavior

The script should execute (adding a default value of True for commit in the run method works fine).

Observed Behavior

A TypeError is raised as commit is not passed to the run method. Error message:

the run() missing 1 required positional argument: commit

Originally created by @certanet on GitHub (Feb 29, 2020). ### Environment * Python version: 3.7.6 * NetBox version: 2.7.8 Using the REST API to call a custom script is not passing the 'commit' parameter into the run method. Using the GUI form works fine, per #4262, but the missing mandatory parameter fails to run the script via API. ### Steps to Reproduce 1. Use the example custom script from https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/ 2. Send a POST to: **URI:** /api/extras/scripts/new_site.NewBranchScript/ **Body:** `{ "data": { "site_name": "123", "switch_count": 2, "switch_model": "Catalyst 3560X-48T" }, "commit": true }` <!-- What did you expect to happen? --> ### Expected Behavior The script should execute (adding a default value of True for commit in the run method works fine). <!-- What happened instead? --> ### Observed Behavior A TypeError is raised as commit is not passed to the run method. Error message: > the run() missing 1 required positional argument: commit
adam added the type: bugstatus: accepted labels 2025-12-29 18:29:01 +01:00
adam closed this issue 2025-12-29 18:29:01 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 2, 2020):

the run() missing 1 required positional argument: commit

This error indicates that the run() method in the script you've written doesn't accept a commit argument. It should look like this:

def run(self, data, commit):
@jeremystretch commented on GitHub (Mar 2, 2020): > the run() missing 1 required positional argument: commit This error indicates that the `run()` method in the script you've written doesn't accept a `commit` argument. It should look like this: ``` def run(self, data, commit): ```
Author
Owner

@certanet commented on GitHub (Mar 2, 2020):

Thanks @jeremystretch, but this was using the example from https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/ which does accept self, data and commit.

To get around it for now I'm using a default value in the method:

def run(self, data, commit=True):

@certanet commented on GitHub (Mar 2, 2020): Thanks @jeremystretch, but this was using the example from https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/ which does accept self, data and commit. To get around it for now I'm using a default value in the method: ` def run(self, data, commit=True):`
Author
Owner

@jeremystretch commented on GitHub (Mar 2, 2020):

Please post the full trace from the exception.

@jeremystretch commented on GitHub (Mar 2, 2020): Please post the full trace from the exception.
Author
Owner

@certanet commented on GitHub (Mar 2, 2020):

When the run method args are:

def run(self, data, commit):

The error is:

The complete exception is provided below:
						

<class 'TypeError'>
run() missing 1 required positional argument: 'commit'

If further assistance is required, please post to the NetBox mailing list.

But it works fine when the run method args are:

def run(self, data, commit=True):

Also, both work fine when ran from the GUI, so looks like it's not being passed from the API.

@certanet commented on GitHub (Mar 2, 2020): When the run method args are: > def run(self, data, commit): The error is: <pre> The complete exception is provided below: </p> <strong>&lt;class &#39;TypeError&#39;&gt;</strong><br /> run() missing 1 required positional argument: &#39;commit&#39; <p> If further assistance is required, please post to the <a href="https://groups.google.com/forum/#!forum/netbox-discuss">NetBox mailing list</a>. </pre> But it works fine when the run method args are: > def run(self, data, commit=True): Also, both work fine when ran from the GUI, so looks like it's not being passed from the API.
Author
Owner

@certanet commented on GitHub (Mar 2, 2020):

I think..
13fcdc0c1e/netbox/extras/api/views.py (L268)
Needs to be
output = script.run(input_serializer.data['data'], input_serializer.data['commit'])
?

@certanet commented on GitHub (Mar 2, 2020): I think.. https://github.com/netbox-community/netbox/blob/13fcdc0c1e30a76b7cfcc0b25a84c93c894ece3a/netbox/extras/api/views.py#L268 Needs to be `output = script.run(input_serializer.data['data'], input_serializer.data['commit'])` ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3428