Local API: option to validate only the submitted fields on update() #18375
Ardnived
started this conversation in
Feature Requests & Ideas
Replies: 1 comment
|
Dug into this a bit more on our end. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
payload.update()validates the whole document on every call. It also validates fields that are not indata. It checks these fields against the stored value. There is no option to validate only the fields indata.Why it matters
We run a background job. The job updates two fields on a published document: a counter and a timestamp. No form uses these fields. A validator added later can block this update. The validator fails on a stored value in a different field. The job did not send that field.
The only workaround we found is
unpublishAllLocales: true. This flag skips validation as a side effect. The flag is documented for unpublish operations. We do not enable localized status, so the flag does not change_statusin our case. We depend on an undocumented side effect, not a supported option.draft: trueis not a workaround. This flag skips the main row write. It does not skip only validation.Proposal
v4 canary already has similar logic for trash and for
unpublishAllLocales. The logic is incollections/operations/utilities/update.ts, inshouldLimitValidationToSubmittedFieldsandfieldsToValidate. This logic validates only the submitted top-level fields. Please expose the same logic as a general Local API option, for exampleupdate({ ..., data, validate: 'submitted' }). We can open a pull request for this.Notes
mainand v4 canary have the same gap. The logic exists in the code. The Local API does not expose it outside trash andunpublishAllLocales.All reactions