Custom Script StringVar is not JSON serializable #9736

Closed
opened 2025-12-29 21:21:52 +01:00 by adam · 3 comments
Owner

Originally created by @willikubny on GitHub (May 24, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.11

Steps to Reproduce

With a StringVar or TextVar as input variable in a NetBox custom script the script is working through the UI, but fails to view through the REST API browser or get/execute with the REST API.

If the StringVar is removed from the NetBox custom script, then the REST API works fine again.

Expected Behavior

StringVar or TextVar in NetBox custom script should be serialized correctly.

Observed Behavior

<class 'TypeError'>

Object of type StringVar is not JSON serializable

Python version: 3.11.6
NetBox version: 4.0.3
Plugins:
netbox_device_support_plugin: 1.0.5
netbox_napalm_plugin: 0.2.0

Originally created by @willikubny on GitHub (May 24, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.3 ### Python Version 3.11 ### Steps to Reproduce With a StringVar or TextVar as input variable in a NetBox custom script the script is working through the UI, but fails to view through the REST API browser or get/execute with the REST API. If the StringVar is removed from the NetBox custom script, then the REST API works fine again. ### Expected Behavior StringVar or TextVar in NetBox custom script should be serialized correctly. ### Observed Behavior <class 'TypeError'> Object of type StringVar is not JSON serializable Python version: 3.11.6 NetBox version: 4.0.3 Plugins: netbox_device_support_plugin: 1.0.5 netbox_napalm_plugin: 0.2.0
adam closed this issue 2025-12-29 21:21:53 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 24, 2024):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (May 24, 2024): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@willikubny commented on GitHub (May 24, 2024):

Sorry for opening a wrong bug. I found my mistake...

I've named the input StringVar variable "description" and that caused the issue. After naming the variable ap_description it's working.

Thank you anyway for your fast response.
Keep up the good work as NetBox is a great product.

@willikubny commented on GitHub (May 24, 2024): Sorry for opening a wrong bug. I found my mistake... I've named the input StringVar variable "description" and that caused the issue. After naming the variable ap_description it's working. Thank you anyway for your fast response. Keep up the good work as NetBox is a great product.
Author
Owner

@llamafilm commented on GitHub (Jul 1, 2024):

I just found this same issue! Took me awhile to figure this out. I would say this is a bug. To reproduce, create a custom script with the following contents. It runs fine in the UI, but /api/extras/scripts throws the exception as the OP described. Renaming the description variable makes it work.

Another effect of this issue is that when creating an Event Rule, the custom script dropdown list is empty.

from extras.scripts import Script, StringVar

class AddDevice(Script):

    class Meta:
        name = "Add Device"

    description = StringVar()

    def run(self, data, commit):
        self.log_debug(data)
        return
@llamafilm commented on GitHub (Jul 1, 2024): I just found this same issue! Took me awhile to figure this out. I would say this is a bug. To reproduce, create a custom script with the following contents. It runs fine in the UI, but /api/extras/scripts throws the exception as the OP described. Renaming the `description` variable makes it work. Another effect of this issue is that when creating an Event Rule, the custom script dropdown list is empty. ```py from extras.scripts import Script, StringVar class AddDevice(Script): class Meta: name = "Add Device" description = StringVar() def run(self, data, commit): self.log_debug(data) return ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9736