Closed
Description
Deployment Type
Self-hosted
NetBox Version
v4.0.5
Python Version
3.11
Steps to Reproduce
This issue can be reproduced in a couple different workflows. This was originally reported in #16328 after we saw this behavior, which we believe was introduced between 3.6.3 and 3.7.7. We have now reproduced this in a clean install of 4.0.5 running inside docker using netbox-docker 2.9.1.
Edits through the API are not impacted.
Option 1 - corruption during edit:
- Create a JSON custom field - set "UI Editable" to "No". Leave the default value as null.
- Create a prefix, it is not necessary to populate the JSON field with a value -- it will default to null
- View the prefix, observe that the JSON custom field shows a value of "-" in the UI due to it being null
- Edit the prefix and click "save" without making any changes
- Observe that the custom value now changes to the quoted string "null"
Option 2 - corruption on creation:
- Create a JSON custom field - set "UI Editable" to "No". Set the default to JSON such as
{"key1":"value1"}
- Create a prefix
- View the prefix, observe that the JSON custom field now shows an escaped string value of
"{\"key1\": \"value1\"}"
- Edit the prefix and click "save" without making any changes
- Observe that the custom value is now escaped again to something like
"\"{\\\"key1\\\": \\\"value1\\\"}\""
- Repeat edit+save (without making changes) and observe that the prefix keeps getting escaped more and more as a JSON string instead of any valid JSON data structure.
Expected Behavior
The JSON value should not be changed due to the UI being set to read-only for this field
Observed Behavior
The server is setting a new and incorrect/corrupt value for this field in the database. The native JSON is being converted to an escaped string