payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
28.82k stars 1.79k forks source link

API still returns defaultLocale value even when fallback is set to false #8443

Open PP-Tom opened 2 months ago

PP-Tom commented 2 months ago

Link to reproduction

No response

Environment Info

Payload: 3.0.0-beta.109
Node: 10.2.4
Next: 15.0.0-canary.170

Describe the Bug

The defaultLocale value for localized fields is still returned even when the fallback value is set to false.

Reproduction Steps

  1. Create a collection.
  2. Add a localized field such as:
    {
    name: 'excerpt',
    type: 'textarea',
    localized: true,
    },
  3. In your payload.config.ts add:
    localization: {
    locales: [
        { label: 'English', code: 'en-GB' },
        { label: 'Spanish', code: 'es' },
        { label: 'Dutch', code: 'nl' },
        { label: 'American', code: 'en-US', fallbackLocale: 'en-GB' },
    ],
    fallback: false,
    defaultLocale: 'en-GB',
    },

    In the frontend create a new page from your collection, give the defaultLocale a value, save and then switch to a different locale, check the API tab, you'll see the excerpt in the response.

Adapters and Plugins

mongo-db, s3-storage

paulpopus commented 2 months ago

My apologies here, closed the issue prematurely without waiting for the PR to be merged, it still hasnt!

Will review and get it merged this week

matteo-naif commented 1 month ago

It also happens to me when I execute the find method with the Local API: although I specify "en-US", if the document doesn't exist, it returns the default locale document (which in my case is "it-IT").

paulpopus commented 2 weeks ago

This will be available in the next release, let us know if you encounter any issues with fallback locales and logic here.

github-actions[bot] commented 2 weeks ago

🚀 This is included in version v3.0.0-beta.130

matteo-naif commented 2 weeks ago

I tested with the following script

async function run() {
  const payload = await getPayload({ config })

  const pages = await payload.find({
    collection: 'pages',
    locale: 'en-US',
    limit: 1
  })

  console.log(pages)
  process.exit(0)
}

run().catch(console.error)

and if I specify the locale en-US I have still a document that doesn't exist in that locale.

{
  docs: [
    {
      id: '66ceee6848cdfa7fb0544740',
      title: undefined,
      order: 0,
      meta: [Object],
      publishDate: '2024-08-28T09:30:04.240Z',
      author: [Object],
      slug: undefined,
      breadcrumbs: [],
      _status: 'published',
      createdAt: '2024-08-28T09:31:20.609Z',
      updatedAt: '2024-11-04T14:26:49.266Z',
      alternates: [Object],
      collectionType: 'pages',
      content: [Object]
    }
  ],
  totalDocs: 27,
  limit: 1,
  totalPages: 27,
  page: 1,
  pagingCounter: 1,
  hasPrevPage: false,
  hasNextPage: true,
  prevPage: null,
  nextPage: 2
}

My localization setting in payload.config is the following, I don't even have the 'en-US' locale (I removed to avoid the problem).

  localization: {
    locales: ['it-IT'],
    defaultLocale: 'it-IT',
    fallback: false,
  }
github-actions[bot] commented 1 week ago

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