Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/senaite/jsonapi/fieldmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions src/senaite/jsonapi/utils.py
Original file line number Diff line number Diff line change
@@ -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