netbox icon indicating copy to clipboard operation
netbox copied to clipboard

CustomField MultiObject returns dict but expects id's

Open PieterL75 opened this issue 2 years ago • 2 comments

NetBox version

v3.2.9

Python version

3.9

Steps to Reproduce

  1. Create a custom field of the multiobject type
  2. create a device that uses that custom field and populate with some data
  3. retrieve the custom field through the API
  4. update the custom field with a new ID
  5. save the device

Expected Behavior

The device with customs fields is updated with the new value's

Observed Behavior

The save of the object fails with the message that a dict is not acceptable, only ID's are allowed

This is because

  • the GET API returns the multiobject custom fields as an array of dicts.
  • the POST API expects only ID's and not dicts

Reason: API GET call returns the expanded dicts for custom_fields multiobjects when adding a new object to the custom_fields, we use the ID of the object This causes the custom_fields to be a mix of dict and id's But the deserializer of the CustomField class expects only ID's

PieterL75 avatar Sep 01 '22 16:09 PieterL75

Created a PR

PieterL75 avatar Sep 27 '22 10:09 PieterL75

pynetbox is affected by this too : https://github.com/netbox-community/pynetbox/issues/501

when doing an .updates() on an object with a customfield of Object/Multiobject, it always returns true. the API is sending the full dict, while only accepting an id. the compare is then done between an array_of_dict and an array_of_int, which is ofcourse always different

I think it needs to be decided if that API will send/accept dicts only or ids only

PieterL75 avatar Oct 13 '22 10:10 PieterL75