[v4] `localize-status` migration unpublishes every document that has a draft newer than its published version
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- mongodb, postgresql, sqlite, typescript
Research direction
Start with the linked MongoDB and Postgres migration files and the named SQLite migration, then compare how each adapter derives and writes locale status; check the corresponding global migrations too. Reproduce the published document with a newer draft and the document with content only in en using the linked script. Done means the migration preserves the intended publication state consistently across adapters and the migration guide documents the behavior for locales without content.
Written by the indexing model from the issue text.
Description
Describe the Bug
The predefined localize-status migration sets the main document's per-locale _status from the document's latest version. On Payload 3, that isn't the document's publication state. Saving a draft on a published document creates a newer version with _status: 'draft', while the main document stays published and keeps serving the published content.
After the migration, such a document is draft in every locale, including locales nobody edited:
- it disappears from
where: { _status: { equals: 'published' } }queries and fromdraft: falsereads, though nobody unpublished it; - the main document still holds the published content. Only its status changed.
Payload 4 itself doesn't behave this way. With the same history on a v4 database (publish en and de, then save a draft in en), the main document stays published in both locales.
Repro output, 4.0.0-beta.7. The document was published in en and de on Payload 3, and its versions are, oldest first: published, published, draft (latest: true):
main doc _status after migration |
find _status: published, en / de |
|
|---|---|---|
| MongoDB | { en: 'draft', de: 'draft' } |
missing / missing |
| Postgres | draft in both docs_locales rows |
missing / missing |
| SQLite | draft in both docs_locales rows |
missing / missing |
| Same history created on v4 (all three) | published in both locales |
found / found |
The same logic is in all three adapters (main at 3eb46cf):
- MongoDB,
migrateLocalizeStatus.ts#L249-L267(collections) and#L296-L310(globals):// Get the latest version for this document to determine status per locale const latestVersions = await connection .collection(versionsCollection) .find({ parent: doc._id }, { session }) .sort({ createdAt: -1 }) .limit(1) - Postgres,
localize-status/migrateMainCollection.ts#L37-L53:ORDER BY v.created_at DESC LIMIT 1per locale.migrateMainGlobal.tsdoes the same. - SQLite:
packages/drizzle/src/sqlite/predefinedMigrations/localize-status/migrateMainCollection.ts, same query.
Expected: the main document keeps the publication state it had. On Payload 3 data, a main document with scalar _status: 'published' is published in its locales, whatever its latest version says. The versions' own statuses can stay as computed.
Related: the adapters disagree on locales without content
Take a published document whose content exists only in en (title: { en }, no de row). On Payload 3, _status isn't localized, so find({ locale: 'de', where: { _status: { equals: 'published' } } }) returns it, and de reads en through fallback. After the migration:
main doc _status after migration |
find _status: published, de |
|
|---|---|---|
| MongoDB | { en: 'published', de: 'published' } |
found |
| Postgres | only an en row (published); no de row |
missing |
| SQLite | only an en row (published); no de row |
missing |
| Same history created on v4 (all three) | en: 'published'; de not published (Mongo stores de: 'draft') |
missing |
Why they differ:
- MongoDB writes a status for every configured locale.
- Postgres and SQLite only
UPDATE ... WHERE _parent_id = ? AND _locale = ?existing_localesrows, so a locale without a row gets no status.
The same v3 database ends up with different publication states depending on the adapter. MongoDB's result also differs from what v4 itself writes for the same history. Either behaviour could be the intended one, but they should agree, and the migration guide should say which one applies.
Link to the code that reproduces this issue
https://github.com/VeiaG/payload-4-reproductions/tree/repro-localize-status-unpublishes-newer-draft
Reproduction Steps
From apps/next after pnpm install:
- MongoDB (in-memory):
pnpm exec payload run ./scripts/localize-status.ts - SQLite:
DEV_DB=sqlite DATABASE_URI_SQLITE=file:./.sqlite/localize-status.db pnpm exec payload run ./scripts/localize-status.ts. Use a fresh file each run, because the script changes the schema. - Postgres:
docker compose up -din the repo root, thenDEV_DB=postgres pnpm exec payload run ./scripts/localize-status.ts. Run it on an empty database. - Postgres through
payload migrate:DEV_DB=postgres LS_STEP=setup pnpm exec payload run ./scripts/localize-status.tsDEV_DB=postgres pnpm exec payload migrate --force-accept-warningDEV_DB=postgres LS_STEP=report pnpm exec payload run ./scripts/localize-status.ts
On every adapter, "draft on top" goes from published to draft in every locale, while the v4 control stays published. For "en only", MongoDB publishes de, and Postgres and SQLite don't.
In a real upgrade, the steps are:
- On Payload 3, publish a document in
enandde. - Save a draft on top of it in one locale.
- Upgrade to v4.
- Run
payload migrate:create --file @payloadcms/db-mongodb/localize-status(or thedb-postgres/db-sqlitevariant), thenpayload migrate.
Which area(s) are affected?
db: mongodb, db: postgres, db: sqlite
Environment Info
payload: 4.0.0-beta.7
@payloadcms/db-mongodb: 4.0.0-beta.7
@payloadcms/db-postgres: 4.0.0-beta.7 (Postgres 17)
@payloadcms/db-sqlite: 4.0.0-beta.7
Node: 24
OS: Windows 11
- Dominant language
- TypeScript
- Stars
- 45.8k
- Forks
- 4.4k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 251
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysPossibly taken @pcbeingused333 claimed this today. OpenBug db: d1-sqlite Payload OSS
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19766 ·
Maintainers usually reply within 1 day
-
Document bar (.doc-controls__content) overflows a 375 px viewport, clips "Created" and fails axe scrollable-region-focusablePossibly taken A pull request linked to this issue is open or already merged. Openarea: ui Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19690 ·
Maintainers usually reply within 1 day
-
[v4] Blocks thumbnails croped 3:2Possibly taken @samiarif02 claimed this 2 days ago. Openarea: ui Bug Payload OSS status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
payloadcms/payload#19609 ·
Maintainers usually reply within 1 day
-
Scheduled publish jobs are not deleted when their document is deleted (string id in the job, raw id in the cleanup)Possibly taken @volodymyrshk claimed this 10 days ago. Openarea: core Bug db: sqlite
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19448 ·
Maintainers usually reply within 1 day
-
plugin-multi-tenant: `isGlobal` collections redirect tenant-scoped users to `/admin` since 3.93.0 (GlobalViewRedirect prop-name mismatch)Possibly taken @JarrodMFlesch claimed this 10 days ago. OpenBug plugin: multi-tenant
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19420 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
milind-soni/OpenMausBot#6730 ·
Maintainers usually reply within 1 day
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day