Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: draft doc validation when duplicating docs#15816

Merged
GermanJablo merged 4 commits intopayloadcms:mainfrom
lcnogueira:fix/duplicate-doc-feature-draft-docs
Mar 3, 2026
Merged

fix: draft doc validation when duplicating docs#15816
GermanJablo merged 4 commits intopayloadcms:mainfrom
lcnogueira:fix/duplicate-doc-feature-draft-docs

Conversation

@lcnogueira
Copy link
Contributor

@lcnogueira lcnogueira commented Mar 2, 2026

What?

This PR defaults the draft value 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.ts was refactored to use the shared parseParams utility instead of manually parsing query parameters.

v3.62.0 (working) — In v3.62.0 of duplicate.ts, the draft parameter was explicitly defaulted to true:

// draft defaults to true, unless explicitly set requested as false
// to prevent the newly duplicated document from being published
const draft = searchParams.get('draft') !== 'false'

v3.77.0 (broken) — In v3.77.0 of duplicate.ts, the endpoint uses parseParams:

const { depth, draft, populate, select, selectedLocales } = parseParams(req.query)

parseParams only sets draft to true if the query string explicitly contains ?draft=true. The admin UI's DuplicateDocument component does not send ?draft=true as a query parameter, so draft is undefined.

The UI does send { _status: 'draft' } in the request body, but that does not influence the draft flag. In createOperation, the validation skip logic depends entirely on the draft argument:

const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig) && !publishAllLocales)
// ...
skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig),

Since draft is undefined, isSavingDraft is false, skipValidation is false, and full validation runs — rejecting the duplicate when any required fields are empty.

How?

By setting the draft value as true by default when it is not set during a duplicate operation:

Fixes #15815

@lcnogueira lcnogueira changed the title [WIP] Default to draft operation when duplicating docs with undefined draft values fix: draft value when duplicating docs Mar 2, 2026
@lcnogueira lcnogueira changed the title fix: draft value when duplicating docs fix: draft doc validation when duplicating docs Mar 2, 2026
@lcnogueira lcnogueira marked this pull request as ready for review March 2, 2026 20:05
@paulpopus paulpopus requested a review from Copilot March 3, 2026 12:38
Inline the duplicate endpoint draft default in parameter destructuring to keep behavior unchanged while reducing temporary variable noise.
@GermanJablo GermanJablo self-requested a review March 3, 2026 12:39
@GermanJablo GermanJablo self-assigned this Mar 3, 2026
@GermanJablo GermanJablo enabled auto-merge (squash) March 3, 2026 12:39
Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

Thank you very much for the deep dive!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 draft to true in 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 draft query 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.

@GermanJablo GermanJablo merged commit f470699 into payloadcms:main Mar 3, 2026
150 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicating a draft document with empty required fields fails validation

3 participants