Skip to content

[Feature] Support polymorphic Object / MultiObject fields from netbox-custom-objects v0.5.0 #12

@Kani999

Description

@Kani999

Summary

netbox-custom-objects v0.5.0 introduced Polymorphic Object Fields, which let an Object or MultiObject Custom Object Type field reference instances of multiple content types through a generic foreign key. The feature is opt-in per field via the is_polymorphic flag, and the set of allowed targets is configured through the related_object_types M2M relation (see upstream issue netboxlabs/netbox-custom-objects#31).

netbox-custom-objects-tab does not appear to handle this case yet: when a Custom Object Type field is marked is_polymorphic=True, the tab does not show up on the referenced objects (or shows up inconsistently / empty), so polymorphic relationships are effectively invisible from the host object's detail view.

Expected behaviour

Given a Custom Object Type Foo with a polymorphic Object/MultiObject field target whose related_object_types includes, say, dcim.device and dcim.interface:

  • Opening a Device that is referenced by one or more Foo instances should display the Custom Objects tab listing those Foo instances.
  • The same should happen on Interface detail views.
  • MultiObject polymorphic fields should be handled the same way as single Object fields (each referenced object gets the tab).
  • The reverse lookup should respect related_name if it has been set on the field (also new-ish upstream — #385).

Current behaviour

For non-polymorphic Object fields (single related_object_type) the tab works as expected. As soon as a field is switched to is_polymorphic=True, the tab does not render on objects of the allowed types.

Steps to reproduce

  1. Install netbox-custom-objects ≥ 0.5.0 and netbox-custom-objects-tab.
  2. Create a Custom Object Type, e.g. Annotation.
  3. Add an Object field target and set:
    • is_polymorphic = True
    • related_object_types = [dcim.device, dcim.interface] (or any 2+ core types)
  4. Create an Annotation instance pointing at an existing Device.
  5. Open that Device → the Custom Objects tab is missing / empty.
  6. Switch the field back to non-polymorphic with related_object_type = dcim.device → the tab appears on the same Device.

Environment

  • NetBox:
  • netbox-custom-objects: 0.5.0
  • netbox-custom-objects-tab:
  • Python / Django:

Notes / pointers

  • Detection logic probably needs to switch from filtering on related_object_type_id to also querying the generic relation when is_polymorphic is true, and iterating over related_object_types.all() to decide on which model classes the tab should be registered.
  • It may also be worth surfacing all polymorphic Custom Object Types that could point at the current object's content type, even if no instance currently does (matches the non-polymorphic behaviour today).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions