Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle object and multi-object custom fields correctly #452

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Littlericket
Copy link

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

  1. Added "object" and "multi-object" to the list of supported types in the NBCustomField data model
  2. 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 just 123
    • For "multi-object" type fields: Convert array of objects to array of IDs
  3. Maintains backward compatibility with all other custom field types

@bb-Ricardo
Copy link
Owner

Thank you so much for the fix. Will have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants