Skip to content

Docs disappear when adding drafts:true #3910

Closed

Description

@silveltman

Link to reproduction

/

Describe the Bug

I had a collection with products on which versions and draft were both NOT enabled. After the collection had been filled through api, i realized this and enabled drafts and versions:

  versions: {
    drafts: true,
  },

When doing this, the entire collection appears empty in the admin panel. When removing the config again, the docs re-appear.

When only adding versions: true all docs appear like normal.

To Reproduce

  1. Create a collection without any versions or draft setting
  2. add docs to this collection (in my case via rest api)
  3. enable versions and drafts using
  versions: {
    drafts: true,
  },

Payload Version

2.0.13

Adapters and Plugins

@payloadcms/db-mongodb

Activity

  1. added
    status: needs-triage
    on Oct 28, 2023
  2. silveltman commented on Oct 28, 2023

    @silveltman
    Author

    I tried manually adding a _status field with value published before enabling drafts. I thought maybe the docs don't show because this field is missing. Unfortunately, this does not solve the problem.

  3. denolfe commented on Oct 28, 2023

    @denolfe
    Member

    We should improve the docs and DX here. Changing a collection with existing data to have drafts will cause this exact behavior. This is not expected to work without manual data migration.

    We have a few options here, but showing a warning and maybe linking to docs and a migration file would be a good start.

  4. JarrodMFlesch commented on Oct 28, 2023

    @JarrodMFlesch
    Contributor

    Something like this would work for you, #434.

    Saving all the docs again will add them to the versions collection, which is where draft enabled collections are queried from when draft:true (this is how the list view queries).

  5. neslob commented on Aug 7, 2024

    @neslob

    this happened for me in 3.0.0-beta.74 when adding versions / drafts to my Posts collection.

    The documentation did not give me a warning or I overlooked it. https://payloadcms.com/docs/beta/versions/overview.

    But found this closed issue.

    Here is my solution.

    Server action.

    'use server';
    
    import { getPayload } from '@payload-api';
    
    export const republishPosts = async () => {
      const payload = await getPayload();
    
      payload.logger.info(`Republishing posts...`);
    
      const allPosts = await payload.find({
        collection: 'posts',
        where: {
          published: { equals: true },
        },
        limit: 5000,
        depth: 0,
      });
    
      payload.logger.info(`Found ${allPosts.totalDocs} posts`);
      for (const post of allPosts.docs) {
        payload.logger.info(`Republishing post: ${post.title}`);
        await payload.update({
          collection: 'posts',
          id: post.id,
          data: {},
        });
      }
    };

    Add to component.

    export default function RepublishButton() {
      return (
        <form action={republishPosts}>
          <Button>Republish Posts</Button>
        </form>
      );
    }

    And to the collection

    export const Posts: CollectionConfig = {
      slug: 'posts',
      admin: {
        components: {
          beforeListTable: [RepublishButton],
        },
      },
      versions: {
        drafts: true,
      },

    Ran it and all posts got republished and are now visible again.

  6. github-actions commented on Sep 6, 2024

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  7. locked as resolved and limited conversation to collaborators on Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions