Custom Field (Type: Object - reference to ASN) prevents REST API changes #6981

Closed
opened 2025-12-29 19:47:26 +01:00 by adam · 2 comments
Owner

Originally created by @whtkam on GitHub (Sep 13, 2022).

NetBox version

v3.3.2

Python version

3.10

Steps to Reproduce

  1. Create Custom Field

  2. Model --> DCIM>device

  3. Name --> ASN

  4. Lable --> as

  5. Group name --> BGP

  6. Type --> Object

  7. Object Type --> IPAM>ASN

  8. Weight --> 100

  9. Filterlogic --> Loose

  10. UI vis --> R/W

  11. Everything else --> default

  12. Select Device and assign a ASN - which works with no Problem (References also works as expected) --> Save

  13. Try to update another custom field of this device (with ASN) using RESTAPI (pynetbox) --> not working

  14. (reading of the values is working - saving is not possible)

Expected Behavior

Update other custom fields with REST API

Observed Behavior

REST-API --> pynetbox script
select_device = nb.dcim.devices.get(name="device_name")
select_device.custom_fields = {"otherfield": "TEST"}
select_result = select_device.save()

Response from the script:

Traceback (most recent call last):
File "C:\XXXX\XXXX\XXXXX\XXXX\netbox_HE_Assign\netbox_cust_device.py", line 51, in
ops_result = he_assign(d_name,d_wart,d_d_wart)
File "C:\XXXX\XXXX\XXXXX\XXXX\netbox_HE_Assign\netbox_cust_device.py", line 31, in he_assign
ops_result = select_device.save()
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 529, in save
updates = self.updates()
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 506, in updates
diff = self._diff()
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 484, in _diff
{fmt_dict(k, v) for k, v in self.serialize(init=True).items()}
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 457, in serialize
ret[i] = flatten_custom(current_val)
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 61, in flatten_custom
return {
File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 62, in
k: v if not isinstance(v, dict) else v["value"] for k, v in custom_dict.items()
KeyError: 'value'

Process finished with exit code 1

Originally created by @whtkam on GitHub (Sep 13, 2022). ### NetBox version v3.3.2 ### Python version 3.10 ### Steps to Reproduce 1. Create Custom Field 2. Model --> DCIM>device 3. Name --> ASN 4. Lable --> as 5. Group name --> BGP 6. Type --> Object 7. Object Type --> IPAM>ASN 8. Weight --> 100 9. Filterlogic --> Loose 10. UI vis --> R/W 11. Everything else --> default 12. Select Device and assign a ASN - which works with no Problem (References also works as expected) --> Save 13. Try to update another custom field of this device (with ASN) using RESTAPI (pynetbox) --> not working 14. (reading of the values is working - saving is not possible) ### Expected Behavior Update other custom fields with REST API ### Observed Behavior REST-API --> pynetbox script select_device = nb.dcim.devices.get(name="device_name") select_device.custom_fields = {"otherfield": "TEST"} select_result = select_device.save() Response from the script: Traceback (most recent call last): File "C:\XXXX\XXXX\XXXXX\XXXX\netbox_HE_Assign\netbox_cust_device.py", line 51, in <module> ops_result = he_assign(d_name,d_wart,d_d_wart) File "C:\XXXX\XXXX\XXXXX\XXXX\netbox_HE_Assign\netbox_cust_device.py", line 31, in he_assign ops_result = select_device.save() File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 529, in save updates = self.updates() File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 506, in updates diff = self._diff() File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 484, in _diff {fmt_dict(k, v) for k, v in self.serialize(init=True).items()} File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 457, in serialize ret[i] = flatten_custom(current_val) File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 61, in flatten_custom return { File "C:\XXXX\XXXX\XXXXX\XXXX\venv\lib\site-packages\pynetbox\core\response.py", line 62, in <dictcomp> k: v if not isinstance(v, dict) else v["value"] for k, v in custom_dict.items() KeyError: 'value' Process finished with exit code 1
adam closed this issue 2025-12-29 19:47:26 +01:00
Author
Owner

@abhi1693 commented on GitHub (Sep 13, 2022):

This is a pynetbox issue and a potential fix exists at https://github.com/netbox-community/pynetbox/pull/472#issuecomment-1163422787 and commit ref can be found at https://github.com/Onemind-Services-LLC/pynetbox/tree/fix/cf

@abhi1693 commented on GitHub (Sep 13, 2022): This is a pynetbox issue and a potential fix exists at https://github.com/netbox-community/pynetbox/pull/472#issuecomment-1163422787 and commit ref can be found at https://github.com/Onemind-Services-LLC/pynetbox/tree/fix/cf
Author
Owner

@jeremystretch commented on GitHub (Sep 13, 2022):

Per the bug report template:

If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox.

As this seems to be related to pynetbox, I'm going to close the issue. If you believe a change to NetBox is necessary, please file a new bug report including the raw API request(s) necessary to replicate the reported behavior. Thanks.

@jeremystretch commented on GitHub (Sep 13, 2022): Per the bug report template: > If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. As this seems to be related to pynetbox, I'm going to close the issue. If you believe a change to NetBox is necessary, please file a new bug report including the raw API request(s) necessary to replicate the reported behavior. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6981