Cover multi-table inheritance in change logged models #10593

Closed
opened 2025-12-29 21:33:29 +01:00 by adam · 1 comment
Owner

Originally created by @alehaa on GitHub (Dec 29, 2024).

Originally assigned to: @alehaa on GitHub.

NetBox version

v4.1.10

Feature type

Change to existing functionality

Triage priority

I volunteer to perform this work (if approved)

Proposed functionality

Currently the serialize_object() utility function checks if the model has the custom_field_data attribute.

f03489f58e/netbox/utilities/serialization.py (L32-L33)

I suggest changing this to check if the key actually exists in the data dictionary.

Use case

A plugin could extend existing NetBox models using multi-table inheritance. However, although the attribute is available on the child model class, the data is actually stored in the parent model. Serializing the object during the automatic creation of the ObjectChange will therefore raise an exception, as the attribute is available, but won't be serialized in the data dictionary.

Although NetBox should not cover serialization for this scenario, changing this would allow plugins more possibilities. NetBox simply wouldn't handle this attribute in this scenario, leaving it to the developer to implement. No exceptions will be thrown either.

Database changes

None

External dependencies

None

Originally created by @alehaa on GitHub (Dec 29, 2024). Originally assigned to: @alehaa on GitHub. ### NetBox version v4.1.10 ### Feature type Change to existing functionality ### Triage priority I volunteer to perform this work (if approved) ### Proposed functionality Currently the `serialize_object()` utility function checks if the model has the `custom_field_data` attribute. https://github.com/netbox-community/netbox/blob/f03489f58ee6452f9b0c60d84364f0c67c96b41e/netbox/utilities/serialization.py#L32-L33 I suggest changing this to check if the key actually exists in the `data` dictionary. ### Use case A plugin could extend existing NetBox models using multi-table inheritance. However, although the attribute is available on the child model class, the data is actually stored in the parent model. Serializing the object during the automatic creation of the `ObjectChange` will therefore raise an exception, as the attribute is available, but won't be serialized in the `data` dictionary. Although NetBox should not cover serialization for this scenario, changing this would allow plugins more possibilities. NetBox simply wouldn't handle this attribute in this scenario, leaving it to the developer to implement. No exceptions will be thrown either. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:33:29 +01:00
adam closed this issue 2025-12-29 21:33:29 +01:00
Author
Owner

@rboucher-me commented on GitHub (Feb 17, 2025):

@alehaa Thanks. Assigned this to you to draft a PR

@rboucher-me commented on GitHub (Feb 17, 2025): @alehaa Thanks. Assigned this to you to draft a PR
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10593