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

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

Originally created by @jeremystretch on GitHub (Mar 12, 2025).

Originally assigned to: @jeremystretch on GitHub.

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.

Originally created by @jeremystretch on GitHub (Mar 12, 2025). Originally assigned to: @jeremystretch on GitHub. ### 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. ```python 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: ```python {'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']} ``` 3. Attempt to deserialize the serialized data back into the object. ```python 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.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:37:14 +01:00
adam closed this issue 2025-12-29 21:37:15 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10882