Skip to content

Conversation

@alehaa
Copy link
Contributor

@alehaa alehaa commented Feb 18, 2025

Fixes: #18277

During serialization, custom fields may be available to a model due to multi-table inheritance, but might not be available in serialized data because only direct fields of the model are covered. Now this attribute is only used if available in serialized data. Models using multi-table inheritance must modify their serialize_object() method to cover parent serialization.

Example

Tested example for child models:

class ChildModel(Tenant):
    def serialize_object(self, exclude=None) -> dict[str, Any]:
        data = self.tenant_ptr.serialize_object(exclude)
        data.update(super().serialize_object(exclude))
        return data

If not defined, only fields of the child are serialized.

During serialization, custom fields may be available to a model due to
multi-table inheritance, but might not be available in serialized data
because only direct fields of the model are covered. Now this attribute
is only used if available in serialized data. Models using multi-table
inheritance must modify their serialize_object() method to cover parent
serialization.
@jeremystretch jeremystretch self-requested a review February 20, 2025 15:05
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alehaa!

@jeremystretch jeremystretch merged commit b5bc0ba into netbox-community:main Feb 20, 2025
3 checks passed
@alehaa alehaa deleted the 18277-multitable-inheritance branch February 20, 2025 19:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover multi-table inheritance in change logged models

2 participants