payloadcms / payloadcms/payload

Referenced documents can still be unpublished

Open
#13,843 6 comments 1 reaction 1 assignee View on GitHub

@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: true or weak: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 _status with the new _status. However, this won't work if we have drafts and autosave enabled, since we are not able to determine if it's changing from published to _status because the user is unpublishing the document or just because they updated any content (since drafts and autosave are enabled).
  • Exposing an unpublish option under admin.components.edit that would allow us to implement this check before effectively unpublishing the document.
Image
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 .env file:
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 Places collection and publish it.
  • Create an entry in the Posts collection and select the place you just published in the Reference to Place Collection field:
Image
  • Open the published Places entry again and ensure you can unpublish it, even though it's being referenced by the Post entry.
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.