Skip to content

Reuploading a file on "Save draft" resets the main collection document's _status to "draft" #16633

@LimChorngUan

Description

@LimChorngUan

Describe the Bug

For an upload enabled collection with drafts enabled, replacing a published file and saving as a draft incorrectly overwrites the main collection document, flipping its _status from "published" to "draft". The document then appears unpublished in the admin UI and to any API query.

Note: This only happens when the file itself is reuploaded.

Expected behaviour: "Save draft" should never mutate the main collection document. The main document should remain _status: "published" and continue to reference the previously published file.

Link to the code that reproduces this issue

https://github.com/LimChorngUan/payload/blob/media-reupload-bug/test/_community/collections/Media/index.ts

Reproduction Steps

Prerequisites:

  • Enabled drafts (versions: { drafts: true }) on media collection
  • Enabled s3storage plugin
  1. On media collection, create a new media document, upload an image, and click Publish. => The main media document has _status: "published".
  2. On that same document, remove the existing image, upload a different image, and click Save draft (do not publish).

=> Observe the main media collection document directly in the database or API tab, that the _status has changed to "draft" => acts like unpublish.

Which area(s) are affected?

area: core

Environment Info

v3.84.1 and v4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions