1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #9223: Fix serialization of array field values in change log

This commit is contained in:
jeremystretch
2022-11-18 11:24:14 -05:00
parent c287641363
commit 0885333b11
3 changed files with 24 additions and 0 deletions

View File

@@ -445,6 +445,10 @@ EXEMPT_PATHS = (
f'/{BASE_PATH}metrics',
)
SERIALIZATION_MODULES = {
'json': 'utilities.serializers.json',
}
#
# Sentry

View File

@@ -0,0 +1,19 @@
from django.contrib.postgres.fields import ArrayField
from django.core.serializers.json import Serializer as Serializer_
from django.utils.encoding import is_protected_type
class Serializer(Serializer_):
"""
Custom extension of Django's JSON serializer to support ArrayFields (see
https://code.djangoproject.com/ticket/33974).
"""
def _value_from_field(self, obj, field):
value = field.value_from_object(obj)
# Handle ArrayFields of protected types
if type(field) is ArrayField:
if not value or is_protected_type(value[0]):
return value
return value if is_protected_type(value) else field.value_to_string(obj)