Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jeremystretch opened this issue May 24, 2024 · 0 comments · Fixed by #16325
Closed

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

jeremystretch opened this issue May 24, 2024 · 0 comments · Fixed by #16325
Assignees
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@jeremystretch
Copy link
Member

jeremystretch commented May 24, 2024

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:

# Exclude any MPTTModel fields
if issubclass(obj.__class__, MPTTModel):
for field in ['level', 'lft', 'rght', 'tree_id']:
data.pop(field)

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.)

# Skip excluded and private (prefixes with an underscore) attributes
for key in list(data.keys()):
if key in exclude or (isinstance(key, str) and key.startswith('_')):
data.pop(key)

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

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application status: under review Further discussion is needed to determine this issue's scope and/or implementation complexity: low Requires minimal effort to implement labels May 24, 2024
@jeremystretch jeremystretch self-assigned this May 24, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant