Updating a published document by ID without `draft: true` puts its pending draft live and unpublishes the document

Aperta
#19,670 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Yuvraj7Yadav ci sta già lavorando.

Dal 17/11/2026.

  • #19693 di @Yuvraj7Yadav — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
node.js, sqlite, typescript
Ambito
backend, database

Direzione di ricerca

Start with packages/payload/src/collections/operations/updateByID.ts, especially the latest-version lookup around lines 240–248, and compare it with the published-document and draft update paths. The linked reproduction in src/repro.ts shows both affected update calls; run pnpm repro to see the failure. Done means an update without draft mode preserves the published content and status while keeping the pending draft and applying the field change as described.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: core Bug Payload OSS
Describe the Bug

A published document has a newer draft on top (the admin shows it as "Changed"). An update by ID that isn't a draft save (no draft, or draft: false, and no _status in the data) then does two things to the live document:

  1. It takes over the content of the pending draft. Every reader of the main document now gets content that no editor published.
  2. It gets _status: 'draft'. Every reader that filters by _status: 'published' loses the document.

There is no error and no warning. The update only wanted to change one unrelated field:

await payload.update({ id, collection: 'posts', data: { price: 120 } })
live document before: { _status: 'published', price: 100, title: 'published title' }
live document after:  { _status: 'draft', price: 120, title: 'pending draft title' }
expected:             { _status: 'published', price: 120, title: 'published title' }

Cause. updateByID reads the latest version as the base for the update, without published: true. With a pending draft, the latest version is that draft, including its _status: 'draft'. The merged result is then written to the main document.

Who runs into it. Mostly writes that don't think about drafts at all: integrations, hooks, jobs and migrations that update a synced or computed field. @payloadcms/plugin-mcp is affected too, because its update tool defaults draft to false, so an update from an AI assistant puts an editor's unfinished draft live.

Versions. Reproduced on 3.93.0 with the linked repo, and on 4.0.0-beta.9 with the same script.

Context. #13267 reported the same steps and was closed as expected behavior. In discussion #15125 the write side was reported again and @GermanJablo called it "a very important bug", to be fixed by the drafts API redesign. That redesign has moved to v5, with the note that bugs around the draft parameter should get their own issue with reproduction steps and don't need to wait for it. This is that issue. #19449 with PR #19537 covers the same mechanism for trash and restore only; the redesign PR #18501 was closed.

Suggested fix. When the update isn't a draft save and the latest version is a pending draft, use the published document as the base, so the main document keeps its published content and its _status. Then apply the same data to the pending draft as a new draft version, so the draft stays on top and doesn't lose the change. We run this as a patch on 3.90.1.

Link to the code that reproduces this issue

https://github.com/fabian-michael-asi/payload-drafts-bare-update-repro

Reproduction Steps
  1. Clone, pnpm install.
  2. Run pnpm repro. It uses a local SQLite file and needs no .env.

The script (src/repro.ts) runs these steps on a posts collection with versions: { drafts: true }, once with no draft argument and once with draft: false:

const { id } = await payload.create({
  collection: 'posts',
  data: { _status: 'published', price: 100, title: 'published title' },
})

await payload.update({ id, collection: 'posts', data: { title: 'pending draft title' }, draft: true })

await payload.update({ id, collection: 'posts', data: { price: 120 } })

await payload.findByID({ id, collection: 'posts' })
  1. Output, the same for both variants:
update without draft
  live document before: { _status: 'published', price: 100, title: 'published title' }
  live document after:  { _status: 'draft', price: 120, title: 'pending draft title' }
  expected:             { _status: 'published', price: 120, title: 'published title' }
  found by a `_status: published` query after: false
Which area(s) are affected?

area: core

Environment Info
Binaries:
  Node: 24.22.2
  npm: 11.19.1
  Yarn: N/A
  pnpm: 12.18.0
Relevant Packages:
  payload: 3.93.0
  @payloadcms/db-sqlite: 3.93.0
  @payloadcms/drizzle: 3.93.0
  @payloadcms/translations: 3.93.0
Operating System:
  Platform: darwin
  Arch: arm64

AI generated

Lingua principale
TypeScript
Stelle
45.8k
Fork
4.4k
Merge medio
3g 4h
PR unite (30g)
210

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di payloadcms/payload

Tutte le issue di payloadcms/payload

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.