TypeError when trying to list custom scripts via API #10232

Closed
opened 2025-12-29 21:28:40 +01:00 by adam · 4 comments
Owner

Originally created by @v0tti on GitHub (Sep 12, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.1.0

Python Version

3.11

Steps to Reproduce

  1. Verify no custom scripts exist in NetBox.
  2. Create an upload a Python file with the following content as a custom script:
from extras.scripts import *

class DemoScript(Script):
    description = StringVar()

    def run(self, data, commit):
        return
  1. Access /api/extras/scripts/. The following error is shown:

Expected Behavior

I expect to get a valid JSON listing all existing custom scripts.

Observed Behavior

A TypeError is raised.

<class 'TypeError'>

Object of type StringVar is not JSON serializable

Python version: 3.11.9
NetBox version: 4.1.0

This only happens if an input like StringVar (also verified with TextVar is defined). The scripts are listed and executed like expected and this issue only affects API requests.

Originally created by @v0tti on GitHub (Sep 12, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.1.0 ### Python Version 3.11 ### Steps to Reproduce 1. Verify no custom scripts exist in NetBox. 3. Create an upload a Python file with the following content as a custom script: ```python from extras.scripts import * class DemoScript(Script): description = StringVar() def run(self, data, commit): return ``` 4. Access `/api/extras/scripts/`. The following error is shown: ### Expected Behavior I expect to get a valid JSON listing all existing custom scripts. ### Observed Behavior A `TypeError` is raised. ``` <class 'TypeError'> Object of type StringVar is not JSON serializable Python version: 3.11.9 NetBox version: 4.1.0 ``` This only happens if an input like `StringVar` (also verified with `TextVar` is defined). The scripts are listed and executed like expected and this issue only affects API requests.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:28:40 +01:00
adam closed this issue 2025-12-29 21:28:40 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 12, 2024):

The description field defined on the Script class collides with its description property (which returns self.Meta.description).

The obvious workaround is to rename the field in the script, but within NetBox we should raise an error for such conflicts and/or namespace the properties somehow.

@jeremystretch commented on GitHub (Sep 12, 2024): The `description` field defined on the Script class collides with its `description` property (which returns `self.Meta.description`). The obvious workaround is to rename the field in the script, but within NetBox we should raise an error for such conflicts and/or namespace the properties somehow.
Author
Owner

@v0tti commented on GitHub (Sep 13, 2024):

Thanks for your comment. I have renamed the description StringVar field on all our custom scripts and the REST API is working fine now.

This was not an issue until we upgraded to NetBox 4.1 and even then only the API was having problems. The scripts themselves worked fine. I also could not find any mention of this in the announced breaking change.

@v0tti commented on GitHub (Sep 13, 2024): Thanks for your comment. I have renamed the `description` `StringVar` field on all our custom scripts and the REST API is working fine now. This was not an issue until we upgraded to NetBox 4.1 and even then only the API was having problems. The scripts themselves worked fine. I also could not find any mention of this in the announced breaking change.
Author
Owner

@arthanson commented on GitHub (Oct 10, 2024):

bumping this down in severity as there is an easy workaround.

@arthanson commented on GitHub (Oct 10, 2024): bumping this down in severity as there is an easy workaround.
Author
Owner

@jeremystretch commented on GitHub (Oct 16, 2024):

We ended up treating this as a documentation issue as there's no clear solution to prevent this.

@jeremystretch commented on GitHub (Oct 16, 2024): We ended up treating this as a documentation issue as there's no clear solution to prevent this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10232