Skip to content

Fix single-valued UID reference fields not settable through the JSON API - #106

Open
ramonski wants to merge 1 commit into
2.xfrom
feature/fix-single-valued-uidreference
Open

Fix single-valued UID reference fields not settable through the JSON API#106
ramonski wants to merge 1 commit into
2.xfrom
feature/fix-single-valued-uidreference

Conversation

@ramonski

@ramonski ramonski commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

UIDReferenceFieldMixin.set always forwards the resolved references to the field setter as a list, even when the field is single-valued. AT UIDReferenceField validators reject a list value with [...] is not supported, so assigning a single-valued reference through @@API/senaite/v1/update (or create) fails — for example a Sample's Specification, Batch, SamplePoint or Template.

The classic ReferenceFieldManager already unwraps single-valued fields to a scalar; the UID reference mixin (used by both the AT and DX UID reference field managers) does not.

Current behavior before PR

Updating a single-valued UID reference field fails:

POST @@API/senaite/v1/update/<sample-uid>
{"Specification": "<spec-uid>"}

-> "['<spec-uid>'] is not supported."

The same happens with {"Specification": {"uid": "<spec-uid>"}}, because the value still reaches the field validator wrapped in a list.

Desired behavior after PR is merged

The reference is assigned. Non multi-valued fields receive a scalar UID (or None to clear); multi-valued fields keep the list, unchanged. DX UIDReferenceField.set already normalizes via to_list, so scalars are accepted there too — the change is safe for both field managers.

--

Reproduced against a live 2.x instance (assigning a Sample Specification). The fix mirrors the single-valued handling in ReferenceFieldManager.

I confirm I have coded it according to PEP8 standards.

The UIDReferenceFieldMixin always passed a list to the field setter, even
for single-valued fields. AT UIDReferenceField validators reject a list
value ('[...] is not supported'), so assigning e.g. a Sample's
Specification, Batch or SamplePoint through the API failed. Unwrap the
list to a scalar (or None to clear) for non multi-valued fields, matching
the classic ReferenceFieldManager.
@ramonski
ramonski requested a review from xispa July 28, 2026 16:49
@ramonski ramonski added the Bug 🐞 Something is broken label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug 🐞 Something is broken

Development

Successfully merging this pull request may close these issues.

1 participant