payloadcms / payloadcms/payload
Referenced documents can still be unpublished
Open
@nathanlentz is already working on this.
Since Aug 18, 2026.
area: core
Bug
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
If one document is being referenced in a relationship field, we can prevent unpublished documents from being added to that field, by using a filter:
return {
_status: {
equals: 'published',
},
};
However, AFTER selecting the published document in the relationship field, that same document can still be unpublished. This causes a lot of issues, since published pages will remain pointing to unpublished documents. I see a few possible solutions, but I'm not sure which one would be the most viable:
- Exposing a flag (i.e.
weak: trueorweak:false) that we could set when creating a relationship field that would throw an error by default if we tried to unpublish a document that is being referenced somewhere. IMHO, this is the ideal solution. - Using a hook to compare the previous
_statuswith the new_status. However, this won't work if we havedraftsandautosaveenabled, since we are not able to determine if it's changing frompublishedto_statusbecause the user is unpublishing the document or just because they updated any content (sincedraftsandautosaveare enabled). - Exposing an
unpublishoption underadmin.components.editthat would allow us to implement this check before effectively unpublishing the document.
Link to the code that reproduces this issue
https://github.com/lcnogueira/payload-draft-published-issue
Reproduction Steps
- Install the packages:
pnpm install. - Ensure you have the proper env variables under your
.envfile:
DATABASE_URI=mongodb://127.0.0.1/drafts-published-bug
PAYLOAD_SECRET=any-string-you-want
- Use docker to start the database:
docker-compose up. - Start the project:
pnpm run dev. - Create an entry in the
Placescollection and publish it. - Create an entry in the
Postscollection and select the place you just published in theReference to Place Collectionfield:
- Open the published
Placesentry again and ensure you can unpublish it, even though it's being referenced by thePostentry.
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
`
Binaries:
Node: 23.11.1
npm: 10.9.2
Yarn: 1.22.19
pnpm: 10.14.0
Relevant Packages:
payload: 3.56.0
next: 15.4.4
@payloadcms/db-mongodb: 3.56.0
@payloadcms/email-nodemailer: 3.56.0
@payloadcms/graphql: 3.56.0
@payloadcms/next/utilities: 3.56.0
@payloadcms/payload-cloud: 3.56.0
@payloadcms/richtext-lexical: 3.56.0
@payloadcms/translations: 3.56.0
@payloadcms/ui/shared: 3.56.0
react: 19.1.0
react-dom: 19.1.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:39 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6020
Available memory (MB): 16384
Available CPU cores: 10
Contributor 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.
Assessment
This issue has not been assessed yet.