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
- Install
netbox-custom-objects ≥ 0.5.0 and netbox-custom-objects-tab.
- Create a Custom Object Type, e.g.
Annotation.
- Add an Object field
target and set:
is_polymorphic = True
related_object_types = [dcim.device, dcim.interface] (or any 2+ core types)
- Create an
Annotation instance pointing at an existing Device.
- Open that Device → the Custom Objects tab is missing / empty.
- 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).
Summary
netbox-custom-objectsv0.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 theis_polymorphicflag, and the set of allowed targets is configured through therelated_object_typesM2M relation (see upstream issue netboxlabs/netbox-custom-objects#31).netbox-custom-objects-tabdoes not appear to handle this case yet: when a Custom Object Type field is markedis_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
Foowith a polymorphic Object/MultiObject fieldtargetwhoserelated_object_typesincludes, say,dcim.deviceanddcim.interface:Fooinstances should display the Custom Objects tab listing thoseFooinstances.related_nameif 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 tois_polymorphic=True, the tab does not render on objects of the allowed types.Steps to reproduce
netbox-custom-objects≥ 0.5.0 andnetbox-custom-objects-tab.Annotation.targetand set:is_polymorphic = Truerelated_object_types = [dcim.device, dcim.interface](or any 2+ core types)Annotationinstance pointing at an existing Device.related_object_type = dcim.device→ the tab appears on the same Device.Environment
netbox-custom-objects: 0.5.0netbox-custom-objects-tab:Notes / pointers
related_object_type_idto also querying the generic relation whenis_polymorphicis true, and iterating overrelated_object_types.all()to decide on which model classes the tab should be registered.