Skip to content

Fix Translation Issue for Unpublished Documents #109

@BM-Buschmann

Description

@BM-Buschmann

Description:
Currently, when a document has not been published, the translation does not take place because findEntityWithConfig only queries payload documents that are published. This occurs because the default behavior of the find query is draft: false.

Steps to Reproduce:

  1. Attempt to retrieve a draft (unpublished) document using findEntityWithConfig.
  2. Observe that the document is not found, leading to missing translations.

Proposed Fix:

To allow translations to work for draft documents, add the draft: true property in the payload queries.

Current Code (Problematic)

const docPromise = isGlobal
  ? payload.findGlobal({
      depth: 0,
      fallbackLocale: undefined,
      locale: locale as any,
      overrideAccess,
      req,
      slug: args.globalSlug as GlobalSlug,
    })
  : payload.findByID({
      collection: collectionSlug as CollectionSlug,
      depth: 0,
      fallbackLocale: undefined,
      id: id as number | string,
      locale: locale as any,
      overrideAccess,
      req,
    });

Updated Code (Fix)

const docPromise = isGlobal
  ? payload.findGlobal({
      depth: 0,
      fallbackLocale: undefined,
      locale: locale as any,
      overrideAccess,
      req,
      slug: args.globalSlug as GlobalSlug,
      draft: true, // Allow retrieval of draft documents
    })
  : payload.findByID({
      collection: collectionSlug as CollectionSlug,
      depth: 0,
      fallbackLocale: undefined,
      id: id as number | string,
      locale: locale as any,
      overrideAccess,
      req,
      draft: true, // Allow retrieval of draft documents
    });

Expected Behavior:

  • Draft (unpublished) documents should be retrievable by findEntityWithConfig, ensuring translations occur correctly.

Environment:

  • Payload Version: 3.23.0
  • Node.js Version: 20.x.x
  • Database: postgressSql

Additional Context:

This fix ensures that draft documents are accessible in the translation workflow, preventing issues where unpublished documents fail to be retrieved.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions