[PR #18664] [MERGED] Fixes 18277: Cover multitable inheritance in serialization #15407

Closed
opened 2025-12-30 00:21:45 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18664
Author: @alehaa
Created: 2/18/2025
Status: Merged
Merged: 2/20/2025
Merged by: @jeremystretch

Base: mainHead: 18277-multitable-inheritance


📝 Commits (1)

  • e2277bc Cover multitable inheritance in serialization

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 netbox/utilities/serialization.py (+1 -1)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18664 **Author:** [@alehaa](https://github.com/alehaa) **Created:** 2/18/2025 **Status:** ✅ Merged **Merged:** 2/20/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `18277-multitable-inheritance` --- ### 📝 Commits (1) - [`e2277bc`](https://github.com/netbox-community/netbox/commit/e2277bc9f6d42106b3149af0579bfc7cddd197d3) Cover multitable inheritance in serialization ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netbox/utilities/serialization.py` (+1 -1) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #18277 <!-- Please include a summary of the proposed changes below. --> 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: ```Python 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:21:45 +01:00
adam closed this issue 2025-12-30 00:21:46 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15407