payloadcms / payloadcms/payload
`publishSpecificLocale` writes `{}` for localized fields that have never been saved in any locale
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
When using "Publish in [locale]" on a document where a localized field has no value saved for any locale yet, the field is written to the database as an empty object {} instead of being absent or null. In practice this affects optional fields most visibly, since required fields are blocked by validation before reaching this code path, but the root cause is not the required flag.
This happens in mergeLocalizedData.ts (default case). When newValue is undefined (field was never touched), the || {} fallback produces {} which gets written to the DB. Fetching the document with locale=all then returns subtitle: {}.
Link to the code that reproduces this issue
https://github.com/acrusella/payload/tree/publish-specific-locale-empty-object/test/_community
Reproduction Steps
- Clone the repo and check out branch
publish-specific-locale-empty-object - Run
pnpm install - Start MongoDB:
docker compose -f test/docker-compose.yml --profile mongodb up -d --wait - Run
pnpm test:int _community - Observe the test fail with
AssertionError: expected {} to not deeply equal {}
The test creates a document leaving an optional localized field empty, then publishes with publishSpecificLocale: 'en' (the "Publish in en" dropdown in the admin UI), then fetches with locale: 'all', the field comes back as {} instead of being absent.
Which area(s) are affected?
area: core
Environment Info
| Payload | 3.83.0 |
| Next.js | 16.2.3 |
| Node.js | 23.11.0 |
| Database | MongoDB |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mergeLocalizedData.ts, especially the default case described in the issue, then run the reproduction under test/_community with pnpm test:int _community after starting MongoDB from test/docker-compose.yml. The fix is complete when publishing a document with an untouched optional localized field no longer stores or returns that field as {} and the integration test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, typescript
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100