Skip to content

deserialize_object() does not account for resolved tags in object data #18884

@jeremystretch

Description

@jeremystretch

Deployment Type

NetBox Cloud

NetBox Version

v4.2.5

Python Version

3.10

Steps to Reproduce

  1. Create an object with one or more tags assigned. (In this example, we use a tenant.)
  2. Serialize the object using the serialize_object() utility function.
from pprint import pprint
from tenancy.models import Tenant
from utilities.serialization import serialize_object, deserialize_object

tenant = Tenant.objects.first()
data = serialize_object(tenant)
pprint(data)

The output data is below:

{'comments': '',
 'created': '2020-12-19T00:00:00Z',
 'custom_fields': {'cust_id': 'CYB01'},
 'description': '',
 'group': 1,
 'last_updated': '2025-03-12T18:02:59.743Z',
 'name': 'Cyberdyne Systems',
 'slug': 'cyberdyne',
 'tags': ['Alpha', 'Bravo', 'Charlie']}
  1. Attempt to deserialize the serialized data back into the object.
deserialize_object(Tenant, data)

Expected Behavior

deserialize_object() should return the deserialized object with all attributes set correctly.

Observed Behavior

A DeserializationError is raised:

django.core.serializers.base.DeserializationError: ['“Alpha” value must be an integer.']: (tenancy.tenant:pk=None) field_value was 'Alpha'

This occurs because the function does not account for the tags being specified by name rather than by numeric primary key.

Metadata

Metadata

Assignees

Labels

severity: mediumResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions