Closed jwbensley closed 8 months ago
You seem to have included a lot of unrelated information in your report, and the reproduction steps rely upon the pynetbox API client. Please rewrite the reproduction steps above to show how the suspect behavior can be reproduced using only the NetBox UI, or (if relevant) using raw API requests.
This is the first bug I guess
If your intent is to report multiple bugs, please open a separate issue for each one.
You seem to have included a lot of unrelated information in your report
-> what would that be, it all seems relevant to me?
and the reproduction steps rely upon the pynetbox API client
-> because as I mentioned, there seems to be a UI bug..
OK, 2nd attempt using only the GUI.
JSON
and it has a default value of an empty JSON array []
, this is applied to devices: []
is gone, the field has been changed to now contain JSON null
: This also happens if the custom field value is an empty JSON object {}
.
It seems that when editing an device, if the custom field value evaluates to boolean False, then when saving my changes, the custom field is updated from []
or {}
to null
.
I tested the reproduction steps on v3.7.0 and I can confirm, this bug still exists.
Deployment Type
Self-hosted
NetBox Version
v3.5.9
Python Version
3.10
Steps to Reproduce
We have a custom field on devices which is a "JSON" type custom field. We store a list of static routes on that device. By default this is just an empty list (JSON array):
Adding data is no problem:
We can see the data in the NetBox GUI too:
Deleting data is no problem:
Again, in the GUI we see the data is gone:
What is important to note here is that on the CLI we see that the value of the custom field is an empty list, the custom field is not empty, even though it looks empty in the GUI.
This is the first bug I guess, the GUI should show an empty JSON array? I'm not really bothered about this personally because I am only using the API. But this is probably a hint to my second/main bug I want to report.
When I edit the device in the GUI I see the custom field value is an empty JSON array:
Here is the configuration of the custom field, the default value is an empty list, so we can just append/pop values from the list, and the import point is that there is always a list to append to/pop from:
Here comes the main bug...
So, we have an empty array stored in the JSON custom field and adding/removing data from that list works as expected.
BUG If the list is empty, and I then edit "something" about the device in the GUI, in this case I will add a tag to the device, the custom field is updated and the empty list is remove, meaning the custom field is now empty/blank/null.
There is a third related bug here too. If I edit the device via the GUI and try to set the custom JSON field value to
[]
and click Save, nothing is saved. If I edit the device again afterwards I see the custom field is empty. I am unable to restore the empty list.Expected Behavior
What I expect is happening here is that the JSON custom field is being checked using a boolean check, something like
if custom_field: ...
and[]
is evaluating toFalse
.When updating a device, JSON fields which are not empty should not be set to
None
/null
. Adding a tag should not remove the empty list. Now the code which appends to that empty list is broken because the list doesn't exist anymore.I should also be able to set the value of a JSON field to
[]
when editing a device via the GUI..Observed Behavior
When updating a device, JSON fields which evaluate to
False
in Python are set toNone
.I am also unable to set a JSON custom field to
[]
when editing a device via the GUI.