Integer arrays serialized as strings in changelog snapshot #6404

Closed
opened 2025-12-29 19:40:17 +01:00 by adam · 5 comments
Owner

Originally created by @jeremystretch on GitHub (Apr 26, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.2.1

Python version

3.8

Steps to Reproduce

  1. Create a service with all required parameters. Set the ports to 80, 8080.
  2. View the creation record in the service's change log

Expected Behavior

The list of designated ports (which are stored on the model as an array of integers) should be recorded as ports: [80, 8080].

Observed Behavior

The ports are serialized as a string: ports: "[\"80\", \"8080\"]".

This seems to be a limitation of Django's built-in JSON serializer, which apparently does not support array types.

Originally created by @jeremystretch on GitHub (Apr 26, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.2.1 ### Python version 3.8 ### Steps to Reproduce 1. Create a service with all required parameters. Set the ports to `80, 8080`. 2. View the creation record in the service's change log ### Expected Behavior The list of designated ports (which are stored on the model as an array of integers) should be recorded as `ports: [80, 8080]`. ### Observed Behavior The ports are serialized as a string: `ports: "[\"80\", \"8080\"]"`. This seems to be a limitation of Django's built-in [JSON serializer](https://github.com/django/django/blob/main/django/core/serializers/json.py), which apparently does not support array types.
adam added the type: bugstatus: accepted labels 2025-12-29 19:40:17 +01:00
adam closed this issue 2025-12-29 19:40:17 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 25, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jun 25, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@arthanson commented on GitHub (Sep 1, 2022):

Created a Django issue: https://code.djangoproject.com/ticket/33974

@arthanson commented on GitHub (Sep 1, 2022): Created a Django issue: https://code.djangoproject.com/ticket/33974
Author
Owner

@arthanson commented on GitHub (Sep 2, 2022):

Closed as wontfix in Django: "Thanks for the report however (de-)serialization works for me with
ArrayField(base_field=models.PositiveSmallIntegerField()). Are there any
practical issues with the current approach (except for your preferences)?
Other complex fields (such as JSONField) are also serialized as strings.
I'm afraid that the proposed change is backward incompatible and you can
always use a custom serializer, if you need a different format."

Will do a workaround.

@arthanson commented on GitHub (Sep 2, 2022): Closed as wontfix in Django: "Thanks for the report however (de-)serialization works for me with `ArrayField(base_field=models.PositiveSmallIntegerField())`. Are there any practical issues with the current approach (except for your preferences)? Other complex fields (such as `JSONField`) are also serialized as strings. I'm afraid that the proposed change is backward incompatible and you can always use a custom serializer, if you need a different format." Will do a workaround.
Author
Owner

@arthanson commented on GitHub (Sep 2, 2022):

I see two potential ways to fix:

  1. Create a new field subclassing an Integer ArrayField that has a value_to_string that will do the correct serialization. Would not only change the change log but also Fixtures (not sure if this would be any issue). Would potentially create a new. migration unless it gets weeded out.
  2. Just change it in the change log serialization code, that field can be popped out of the standard serializer and then serialized correctly. Would only effect the change log codepath.

@jeremystretch I'm leaning towards 1 unless there are side-effects I'm not aware of or you have a preference?

@arthanson commented on GitHub (Sep 2, 2022): I see two potential ways to fix: 1. Create a new field subclassing an Integer ArrayField that has a value_to_string that will do the correct serialization. Would not only change the change log but also Fixtures (not sure if this would be any issue). Would potentially create a new. migration unless it gets weeded out. 2. Just change it in the change log serialization code, that field can be popped out of the standard serializer and then serialized correctly. Would only effect the change log codepath. @jeremystretch I'm leaning towards 1 unless there are side-effects I'm not aware of or you have a preference?
Author
Owner

@jeremystretch commented on GitHub (Nov 18, 2022):

@arthanson I don't see any reason to modify the field itself; this issue seems wholly contained to a limitation in Django's JSON serializer. It looks like we'll have to implement our own custom serializer to ensure the correct serialization of array data unfortunately.

@jeremystretch commented on GitHub (Nov 18, 2022): @arthanson I don't see any reason to modify the field itself; this issue seems wholly contained to a limitation in Django's JSON serializer. It looks like we'll have to implement our own custom serializer to ensure the correct serialization of array data unfortunately.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6404