Include "private" fields when serializing objects for change logging #9741

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

Originally created by @jeremystretch on GitHub (May 24, 2024).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.0.3

Feature type

Change to existing functionality

Proposed functionality

When logging the creation, change, or deletion of an object, NetBox serializes the Python instance using the serialize_object() utility function. This wraps Django's internal serialization function, with some caveats. First, we ignore MPTT internal fields:

103c08c2d2/netbox/utilities/serialization.py (L33-L36)

Second, we omit any "private" fields; those which begin with an underscore. (This is done purely as a means of noise reduction, and not in the interest of privacy or security.)

103c08c2d2/netbox/utilities/serialization.py (L48-L51)

This issue proposes that we stop omitting these fields from the serialized data. Where it makes sense to omit these fields from display (e.g. when rendering a diff in the change log), the fields can be omitted from the output.

Use case

The exclusion of MPTT internal fields poses an issue for the staged changes API, which has been captured in #13422.

The omission of certain private fields can pose similar problems. For instance, omitting the _name field when serializing a site fails to capture the naturalized form of the site's name. When attempting to restore a site from serialized data using deserialize_object(), the resulting instance will be saved to the database with an empty value for _name, leading to issues with query ordering.

Database changes

None

External dependencies

None

Originally created by @jeremystretch on GitHub (May 24, 2024). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.0.3 ### Feature type Change to existing functionality ### Proposed functionality When logging the creation, change, or deletion of an object, NetBox serializes the Python instance using the [`serialize_object()`](https://github.com/netbox-community/netbox/blob/103c08c2d2bc3e32d8274b8d8ec8dd2380857388/netbox/utilities/serialization.py#L15) utility function. This wraps Django's internal serialization function, with some caveats. First, we ignore MPTT internal fields: https://github.com/netbox-community/netbox/blob/103c08c2d2bc3e32d8274b8d8ec8dd2380857388/netbox/utilities/serialization.py#L33-L36 Second, we omit any "private" fields; those which begin with an underscore. (This is done purely as a means of noise reduction, and not in the interest of privacy or security.) https://github.com/netbox-community/netbox/blob/103c08c2d2bc3e32d8274b8d8ec8dd2380857388/netbox/utilities/serialization.py#L48-L51 This issue proposes that we stop omitting these fields from the serialized data. Where it makes sense to omit these fields from display (e.g. when rendering a diff in the change log), the fields can be omitted from the output. ### Use case The exclusion of MPTT internal fields poses an issue for the [staged changes API](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/staged-changes/), which has been captured in #13422. The omission of certain private fields can pose similar problems. For instance, omitting the `_name` field when serializing a site fails to capture the naturalized form of the site's name. When attempting to restore a site from serialized data using [`deserialize_object()`](https://github.com/netbox-community/netbox/blob/103c08c2d2bc3e32d8274b8d8ec8dd2380857388/netbox/utilities/serialization.py#L48), the resulting instance will be saved to the database with an empty value for `_name`, leading to issues with query ordering. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:21:56 +01:00
adam closed this issue 2025-12-29 21:21:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9741