fix: restoreVersion validation for localized required fields#15821
Conversation
Run restoreVersion validation in a default-locale context while preserving all locale data, so restoring versions no longer fails when non-default locales are empty.
| collection: collectionConfig.slug, | ||
| limit: 1, | ||
| locale: locale!, | ||
| locale: 'all', |
There was a problem hiding this comment.
restore logic needs full localized data, not just the caller locale.
Without this, localized required fields can appear missing simply because the active locale has no value.
| }) | ||
|
|
||
| // originalDoc with hoisted localized data | ||
| const validationLocale = payload.config.localization?.defaultLocale || locale |
There was a problem hiding this comment.
field validation/hook flow expects locale-hoisted values and should validate restore against the canonical locale context, not a potentially empty non-default locale.
This is what prevents false validation failures when de is empty but en is valid.
Rename reqWithAllLocales to reqWithValidationLocale for clearer intent in the restoreVersion validation flow.
Use a non-null locale fallback when localization is disabled so restoreVersion build types pass under strict union checks.
|
This all looks good. Hopefully the |
|
🚀 This is included in version v3.79.0 |
Summary
restoreVersionto read version/current docs with all locales before restore processingCloses #15698
Related
#15698
Changes
packages/payload/src/collections/operations/restoreVersion.tstest/versions/int.spec.tsTesting
PAYLOAD_DATABASE=sqlite NODE_OPTIONS="--no-deprecation --no-experimental-strip-types" NODE_NO_WARNINGS=1 DISABLE_LOGGING=true pnpm exec vitest --project int test/versions/int.spec.ts -t "should restore published version with correct data|should restore a published version when required localized fields are empty in a non-default locale"