Skip to content

Cover multi-table inheritance in change logged models #18277

@alehaa

Description

@alehaa

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.

if hasattr(obj, 'custom_field_data'):
data['custom_fields'] = data.pop('custom_field_data')

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

Metadata

Metadata

Assignees

Labels

complexity: lowRequires minimal effort to implementstatus: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions