Skip to content

fix: restoreVersion validation for localized required fields#15821

Merged
GermanJablo merged 3 commits intopayloadcms:mainfrom
GermanJablo:issue-15698-restoreversion-locale-validation
Mar 3, 2026
Merged

fix: restoreVersion validation for localized required fields#15821
GermanJablo merged 3 commits intopayloadcms:mainfrom
GermanJablo:issue-15698-restoreversion-locale-validation

Conversation

@GermanJablo
Copy link
Copy Markdown
Contributor

Summary

  • fix collection restoreVersion to read version/current docs with all locales before restore processing
  • validate restore data in the default locale context while preserving full locale data for persistence
  • add an integration regression test for restoring versions when required localized fields are empty in a non-default locale

Closes #15698

Related

#15698

Changes

  • update packages/payload/src/collections/operations/restoreVersion.ts
  • add coverage in test/versions/int.spec.ts

Testing

  • 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"

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',
Copy link
Copy Markdown
Contributor Author

@GermanJablo GermanJablo Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@GermanJablo GermanJablo enabled auto-merge (squash) March 3, 2026 17:12
@JessRynkar
Copy link
Copy Markdown
Member

This all looks good. Hopefully the locale toggles on the version view are not misleading, users should be aware that this function will restore the entire version across locales. In the future, we might want to allow this on a per-locale basis.

@GermanJablo GermanJablo merged commit e899182 into payloadcms:main Mar 3, 2026
150 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 4, 2026

🚀 This is included in version v3.79.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restoreVersion fails validation on localized and required fields when non-default locales are empty or filled

2 participants