fix: handle object and multi-object custom fields correctly
Fix Custom Fields with object/multi-object type handling #451
Problem
When patching NetBox objects with custom fields of type "object" or "multi-object", netbox-sync tries to use the complete object representation received from the API instead of just the required object IDs. This causes errors like:
NetBox returned body: {'custom_fields': ["Cannot resolve keyword 'display' into field. [...]
The API returns object references in custom fields with properties like id, url, display, and name, but when patching, NetBox only expects the ID(s) of the referenced object(s).
Solution
Modified the update method in the NetBoxObject class to properly handle custom fields of type "object" and "multi-object". When patching values:
- For "object" type fields: Extract only the ID from the object representation
- For "multi-object" type fields: Extract an array of IDs from the object representations
Implementation Details
- Added "object" and "multi-object" to the list of supported types in the NBCustomField data model
- Implemented a pre-processing step for custom field values:
- Added logic to determine the custom field type by querying the inventory
- For "object" type fields: Convert
{"id": 123, "display": "Object", ...}to just123 - For "multi-object" type fields: Convert array of objects to array of IDs
- Maintains backward compatibility with all other custom field types
Thank you so much for the fix. Will have a look at it.
Hi @bb-Ricardo , can you update on this? Theres a bunch of devices and VMs which arent "updating" or stopped updating because of this. For example, having a custom field with a linked object type will always fail after netbox-sync tries an PATCH.