diff --git a/docs/changelog.rst b/docs/changelog.rst index cecfa7c..8b70edc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,7 @@ Changelog 2.7.0 (unreleased) ------------------ +- #75 Fix to encode UTF-8 to pass UIDReferenceField validation - #73 Update setter method name generation in DexterityDataManager - #69 Allow to pass in physical paths for create/update endpoints - #68 Fix AT field validation diff --git a/src/senaite/jsonapi/fieldmanagers.py b/src/senaite/jsonapi/fieldmanagers.py index e044f9f..cc27d30 100644 --- a/src/senaite/jsonapi/fieldmanagers.py +++ b/src/senaite/jsonapi/fieldmanagers.py @@ -28,6 +28,7 @@ from senaite.jsonapi import logger from senaite.jsonapi import underscore as u from senaite.jsonapi.interfaces import IFieldManager +from senaite.jsonapi.utils import to_utf8 from zope import interface from zope.interface import implementer from zope.schema._bootstrapinterfaces import WrongContainedType @@ -619,6 +620,7 @@ def set(self, instance, value, **kw): # noqa # Always handle the value as a list values = u.to_list(value) + values = to_utf8(values) for v in values: if api.is_uid(v): diff --git a/src/senaite/jsonapi/utils.py b/src/senaite/jsonapi/utils.py new file mode 100644 index 0000000..20c6c08 --- /dev/null +++ b/src/senaite/jsonapi/utils.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SENAITE.JSONAPI. +# +# SENAITE.JSONAPI is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright 2017-2025 by it's authors. +# Some rights reserved, see README and LICENSE. + +import six + + +def to_utf8(value): + if isinstance(value, six.text_type): + return value.encode("utf-8") + elif isinstance(value, list): + return map(to_utf8, value) + elif isinstance(value, dict): + return { + to_utf8(key): to_utf8(value) + for key, value in six.iteritems(value) + } + return value