Updating a published document by ID without `draft: true` puts its pending draft live and unpublishes the document
I maintainer di solito rispondono entro 1 giorno
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
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
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:
- It takes over the content of the pending draft. Every reader of the main document now gets content that no editor published.
- 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
- Clone,
pnpm install. - 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' })
- 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
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
area: ui Bug Payload OSS
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
payloadcms/payload#19839 ·
I maintainer di solito rispondono entro 1 giorno
-
Accessibility: list row and select-all checkboxes still unnamed in 3.x (#17376 fix not in 3.91)ApertaBug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
payloadcms/payload#19837 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19835 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19833 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19832 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
[BUG]: Shared links drop the configured basePath on GitHub PagesForse già presa @anshulchikhale30-p l’ha presa oggi. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add: GTrekkerApertacheck:passed streams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
I maintainer di solito rispondono entro 1 giorno