Skip to content

Validate only the submitted fields on update - #107

Open
ramonski wants to merge 1 commit into
2.xfrom
feature/partial-update-validation
Open

ramonski wants to merge 1 commit into
2.xfrom
feature/partial-update-validation

Conversation

@ramonski

@ramonski ramonski commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

update_object_with_data re-validates the whole object after applying the record. The field managers already validate each submitted field on set, so this second pass only re-checks fields the caller never touched, and it fails when one of them no longer passes a full validation: an Archetypes field holding a stored legacy value, or a Dexterity behavior invariant such as IExcludeFromNavigationDefault. In practice this blocks partial updates to setup objects (for example toggling a single bika_setup flag, or setting a Sample's Specification), even though the submitted field itself is valid.

This skips the redundant whole-object validation on the update route. Each submitted field is still validated on set (so invalid input is still rejected), while creation keeps validating the full object, preserving the behavior added in #66.

Current behavior before PR

A partial update (POST update/<uid> with a single field) runs a full-object validation and can return 400 with errors for untouched fields, or fail on a behavior invariant.

Desired behavior after PR is merged

The update only validates the fields that were submitted; unrelated untouched fields are left alone. Submitting an invalid field is still rejected. Covered by a new Partial validation on update section in update.rst.

--
I confirm I have coded it according to PEP8 standards.

ramonski added a commit that referenced this pull request Jul 28, 2026
@ramonski
ramonski force-pushed the feature/partial-update-validation branch 2 times, most recently from 417c35d to 0ac89e4 Compare July 28, 2026 18:00
@ramonski
ramonski requested a review from xispa July 28, 2026 18:20
@ramonski ramonski added the Enhancement ✨ Improvement to existing functionality label Jul 28, 2026
@ramonski
ramonski force-pushed the feature/partial-update-validation branch from 0ac89e4 to 9bd7a20 Compare July 28, 2026 18:21
@ramonski
ramonski changed the base branch from 2.x to feature/fix-single-valued-uidreference July 28, 2026 18:21
Base automatically changed from feature/fix-single-valued-uidreference to 2.x October 6, 2026 10:55
@ramonski
ramonski force-pushed the feature/partial-update-validation branch 2 times, most recently from 5b7828f to 23fa4d2 Compare October 6, 2026 11:28
@ramonski

ramonski commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the current 2.x, and the change had to be rewritten rather than replayed.

When this branch was first written, update_items and update_object_with_data still lived in senaite/jsonapi/api/__init__.py. #97 moved them to api/mutation.py, so the original commit no longer applied anywhere. The same change now sits in mutation.py: update_object_with_data takes a partial flag, the two call sites on the update route pass partial=True, and create_object keeps the full validation.

One thing is new since the commit was written. 2.x now skips the whole-object validation for a custom IUpdate adapter, because such an adapter assembles the object through domain operations. That branch is untouched here; the flag only applies to the field-manager path below it.

The branch also carried the commit of #106, which is on 2.x now. It is dropped, so the diff is this change alone.

bin/test-senaite -s senaite.jsonapi: 38 tests, 0 failures, 0 errors.

update_object_with_data re-validated the whole object after applying
the record. The field managers already validate each submitted field on
set, so that second pass only re-checks untouched fields, and fails when
one of them no longer passes a full validation on its own: an Archetypes
field holding a stored legacy value, or a Dexterity behavior invariant
such as IExcludeFromNavigationDefault. A partial update of a setup
object was refused even when the submitted field itself was fine.

Creation still validates the whole object, which is what #66 is about.

Rewritten against the current 2.x: the route helpers moved to
api/mutation in #97 after this change was first written.
@ramonski
ramonski force-pushed the feature/partial-update-validation branch from 23fa4d2 to 8b53ce3 Compare October 6, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement ✨ Improvement to existing functionality

Development

Successfully merging this pull request may close these issues.

1 participant