Error unsetting or updating custom field (multi-)object via API #7323

Closed
opened 2025-12-29 20:21:45 +01:00 by adam · 1 comment
Owner

Originally created by @alegru on GitHub (Dec 5, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.9

Python version

3.9

Steps to Reproduce

Create a custom field object and multiobject (here: for dcim.device)
Edit a device and fill the new custom fields via UI.
Try unsetting the custom fields via REST API, for example:

curl -X 'PATCH'
'http://localhost:8000/api/dcim/devices/1/'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: Token token'
-d '{
"custom_fields": {
"object_field": null
}
}'

and

curl -X 'PATCH'
'http://localhost:8000/api/dcim/devices/1/'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: Token token'
-d '{
"custom_fields": {
"multiobject_field": null
}
}'

Also, try updating the object with the full payload received when querying the API:

curl -X 'PATCH'
'http://localhost:8000/api/dcim/devices/1/'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: Token token'
-d '{
"custom_fields": {
"object_field": {"id": 2, "url": "http://localhost:8000/api/dcim/devices/2/", "display": "testdevice", "name": "testdevice"}
}
}'

curl -X 'PATCH'
'http://localhost:8000/api/dcim/devices/1/'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'Authorization: Token token'
-d '{
"custom_fields": {
"multiobject_field": [{"id": 2, "url": "http://localhost:8000/api/dcim/devices/2/", "display": "testdevice", "name": "testdevice"}]
}
}'

Expected Behavior

The custom fields of the object should be cleared in the first example, and updated in the second.

Observed Behavior

The examples yield variations of an "Unknown related object" error message.
Unsetting custom fields:
{"custom_fields":["Unknown related object(s): None"]}

Updating custom field object as received from the API:
{"custom_fields":["Unknown related object(s): {'id': 1, 'url': 'http://localhost:8000/api/dcim/devices/1/', 'display': 'testdevice', 'name': 'testdevice'}"]}

Updating custom field multiobject as received from the API:
{"custom_fields":["Unknown related object(s): [{'id': 1, 'url': 'http://localhost:8000/api/dcim/devices/1/', 'display': 'testdevice', 'name': 'testdevice'}]"]}

Originally created by @alegru on GitHub (Dec 5, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.9 ### Python version 3.9 ### Steps to Reproduce Create a custom field object and multiobject (here: for dcim.device) Edit a device and fill the new custom fields via UI. Try unsetting the custom fields via REST API, for example: curl -X 'PATCH' \ 'http://localhost:8000/api/dcim/devices/1/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Token token' \ -d '{ "custom_fields": { "object_field": null } }' and curl -X 'PATCH' \ 'http://localhost:8000/api/dcim/devices/1/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Token token' \ -d '{ "custom_fields": { "multiobject_field": null } }' Also, try updating the object with the full payload received when querying the API: curl -X 'PATCH' \ 'http://localhost:8000/api/dcim/devices/1/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Token token' \ -d '{ "custom_fields": { "object_field": {"id": 2, "url": "http://localhost:8000/api/dcim/devices/2/", "display": "testdevice", "name": "testdevice"} } }' curl -X 'PATCH' \ 'http://localhost:8000/api/dcim/devices/1/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Token token' \ -d '{ "custom_fields": { "multiobject_field": [{"id": 2, "url": "http://localhost:8000/api/dcim/devices/2/", "display": "testdevice", "name": "testdevice"}] } }' ### Expected Behavior The custom fields of the object should be cleared in the first example, and updated in the second. ### Observed Behavior The examples yield variations of an "Unknown related object" error message. Unsetting custom fields: {"custom_fields":["Unknown related object(s): None"]} Updating custom field object as received from the API: {"custom_fields":["Unknown related object(s): {'id': 1, 'url': 'http://localhost:8000/api/dcim/devices/1/', 'display': 'testdevice', 'name': 'testdevice'}"]} Updating custom field multiobject as received from the API: {"custom_fields":["Unknown related object(s): [{'id': 1, 'url': 'http://localhost:8000/api/dcim/devices/1/', 'display': 'testdevice', 'name': 'testdevice'}]"]}
adam added the type: bugstatus: accepted labels 2025-12-29 20:21:45 +01:00
adam closed this issue 2025-12-29 20:21:45 +01:00
Author
Owner

@alegru commented on GitHub (Dec 5, 2022):

related commit:
d5538c1ca3

@alegru commented on GitHub (Dec 5, 2022): related commit: d5538c1ca3d7ef7ca2d457ce22bbc645b8b65505
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7323