Skip to content

Add support for attribute assignment to deserialize_object() utility #20277

@jeremystretch

Description

@jeremystretch

NetBox version

v4.4.0

Feature type

Change to existing functionality

Proposed functionality

Tweak the deserialize_object() function in utilities.serialization to support assigning object attributes from serialized data. Currently, only the assignment of values to model fields is supported, due to how Django's native deserialization works.

For example, given the following model:

class Foo(models.Model):
    name = models.CharField()
    number = models.IntegerField()

The following code should set a = True on the resulting instance, even though a is not a field on the model:

deserialize_object(Foo, {
    "name": "Test",
    "number": 123,
    "a": True,
})

Use case

This will expand the usefulness of the function, allowing it to serve additional use cases.

Database changes

N/A

External dependencies

N/A

Metadata

Metadata

Assignees

Labels

complexity: lowRequires minimal effort to implementstatus: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions