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 @@ -15,6 +15,7 @@ Changelog
applied. Uninstalling from the same panel removes the PAS plugin
and the per-user JWT signing secrets.

- #106 Fix single-valued UID reference fields not settable through the JSON API
- #94 Extract registry and settings helpers to api/settings
- #93 Convert api module into a package and extract user helpers
- #92 Restrict /registry, /settings, /users to prevent info leaks
Expand Down
12 changes: 8 additions & 4 deletions src/senaite/jsonapi/fieldmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,18 @@ def set(self, instance, value, **kw): # noqa
elif api.is_path(v):
refs.append(api.get_object_by_path(v))

# Handle non multi valued fields
# convert all references to UIDs
refs = [str(api.get_uid(ref)) for ref in refs if ref]

# Single valued fields expect a scalar value, not a list. Passing a
# list makes the field validator of e.g. an AT UIDReferenceField
# reject the value with "[...] is not supported", so unwrap it here
# (None clears the reference). Multi valued fields keep the list.
if not self.multi_valued:
if len(refs) > 1:
raise ValueError("Multiple values given for single valued "
"field {}".format(repr(self.field)))

# convert all references to UIDs
refs = [str(api.get_uid(ref)) for ref in refs if ref]
refs = refs[0] if refs else None

return self._set(instance, refs, **kw)

Expand Down
Loading