Fix single-valued UID reference fields not settable through the JSON API - #106
Open
ramonski wants to merge 1 commit into
Open
Fix single-valued UID reference fields not settable through the JSON API#106ramonski wants to merge 1 commit into
ramonski wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the issue/feature this PR addresses
UIDReferenceFieldMixin.setalways forwards the resolved references to the field setter as a list, even when the field is single-valued. ATUIDReferenceFieldvalidators reject a list value with[...] is not supported, so assigning a single-valued reference through@@API/senaite/v1/update(orcreate) fails — for example a Sample'sSpecification,Batch,SamplePointorTemplate.The classic
ReferenceFieldManageralready 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:
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
Noneto clear); multi-valued fields keep the list, unchanged. DXUIDReferenceField.setalready normalizes viato_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 inReferenceFieldManager.I confirm I have coded it according to PEP8 standards.