-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
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.
netbox/netbox/utilities/serialization.py
Lines 32 to 33 in f03489f
| 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