fix: draft doc validation when duplicating docs#15816
Merged
GermanJablo merged 4 commits intopayloadcms:mainfrom Mar 3, 2026
Merged
fix: draft doc validation when duplicating docs#15816GermanJablo merged 4 commits intopayloadcms:mainfrom
GermanJablo merged 4 commits intopayloadcms:mainfrom
Conversation
Inline the duplicate endpoint draft default in parameter destructuring to keep behavior unchanged while reducing temporary variable noise.
GermanJablo
approved these changes
Mar 3, 2026
Contributor
GermanJablo
left a comment
There was a problem hiding this comment.
Thank you very much for the deep dive!
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the REST duplicate endpoint where duplicating a draft document could incorrectly trigger full required-field validation when the draft query param is omitted (as the Admin UI does).
Changes:
- Default
drafttotruein the REST duplicate handler when not explicitly provided. - Add integration tests covering draft duplication with missing required fields via both Local API and REST (without an explicit
draftquery param).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/versions/int.spec.ts | Adds regression tests ensuring draft duplication succeeds without required-field validation, including the Admin-UI-like REST request shape. |
| packages/payload/src/collections/endpoints/duplicate.ts | Restores historical behavior by defaulting draft to true when absent, preventing unintended validation on draft duplicates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
What?
This PR defaults the
draftvalue to true when it is not set during a duplicate operation.Why?
It validates the required fields even if the user is trying to duplicate a draft doc.
The regression was introduced when
packages/payload/src/collections/endpoints/duplicate.tswas refactored to use the sharedparseParamsutility instead of manually parsing query parameters.v3.62.0 (working) — In v3.62.0 of
duplicate.ts, thedraftparameter was explicitly defaulted totrue:v3.77.0 (broken) — In v3.77.0 of
duplicate.ts, the endpoint usesparseParams:parseParamsonly setsdrafttotrueif the query string explicitly contains?draft=true. The admin UI'sDuplicateDocumentcomponent does not send?draft=trueas a query parameter, sodraftisundefined.The UI does send
{ _status: 'draft' }in the request body, but that does not influence thedraftflag. IncreateOperation, the validation skip logic depends entirely on thedraftargument:Since
draftisundefined,isSavingDraftisfalse,skipValidationisfalse, and full validation runs — rejecting the duplicate when any required fields are empty.How?
By setting the
draftvalue astrueby default when it is not set during a duplicate operation:Fixes #15815