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

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

Originally created by @jeremystretch on GitHub (Sep 5, 2025).

Originally assigned to: @jeremystretch on GitHub.

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

Originally created by @jeremystretch on GitHub (Sep 5, 2025). Originally assigned to: @jeremystretch on GitHub. ### 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](https://docs.djangoproject.com/en/5.2/topics/serialization/#deserializing-data) works. For example, given the following model: ```python 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: ```python 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
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:47:05 +01:00
adam closed this issue 2025-12-29 21:47:06 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11579