Skip to content

Single-locale update on non-localized blocks field throws "Value must be unique" on nested block IDs (regression of #11309) #16405

Closed

Description

@cafaroo

Link to reproduction

https://github.com/cafaroo/Makebelieve-landing-page/pull/49 (private repo — repro snippets inlined below)

Describe the Bug

`payload.update({ collection, id, locale: 'sv', data: { blocks: [...] } })` throws `ValidationError: "The following field is invalid: id"` with `data.errors: [{ message: "Value must be unique", path: "id" }]` when the `blocks` field is non-localized but contains localized inner fields, and the blocks array passed back contains the `id` keys returned from a prior `find`.

This is the same root cause as #11309 ("Copy To Locale" error) which was partially fixed in PR #11402 by stripping the top-level `id` from update payloads. The fix did not address nested block-array IDs, which still trigger the same primary key constraint violation on `pages_blocks_*_pkey`.

Reproduction Steps

  1. Define a collection with a non-localized `blocks` field where inner fields are `localized: true`. Versioning enabled.

```ts
// collections/Pages.ts
{
slug: 'pages',
versions: { drafts: { autosave: { interval: 2000 } }, maxPerDoc: 25 },
fields: [
{ name: 'title', type: 'text', localized: true },
{
name: 'blocks',
type: 'blocks',
blocks: [
{
slug: 'hero',
fields: [
{ name: 'badge', type: 'text', localized: true },
{ name: 'titleLine1', type: 'text', required: true, localized: true },
{ name: 'image', type: 'upload', relationTo: 'media', required: true },
],
},
],
},
],
}
```

  1. Populate the doc with EN-locale data (works).
  2. Try to add SV-locale text on the same blocks:

```ts
const en = await payload.find({ collection: 'pages', where: { slug: { equals: 'home' } }, locale: 'en', limit: 1, depth: 0 });
const blocks = en.docs[0].blocks; // each has the id Payload assigned
const svBlocks = blocks.map(b => ({ ...b, badge: 'SV badge', titleLine1: 'SV title' }));

await payload.update({
collection: 'pages',
id: en.docs[0].id,
locale: 'sv',
data: { blocks: svBlocks },
});
```

Result

```json
{
"name": "ValidationError",
"message": "The following field is invalid: id",
"data": {
"errors": [{ "message": "Value must be unique", "path": "id" }],
"collection": "pages"
}
}
```

Stack points to `Object.updateOne` inside Payload runtime.

Expected behavior

`payload.update` with a non-default `locale` and the same block IDs as the existing rows should write the localized fields to the corresponding `*_locales` rows and leave non-localized columns intact, mirroring the "Copy To Locale" UI pattern.

Workarounds we tried

  1. `stripIdsDeep` (recursive id removal) — bypassed the validation error but Payload then DELETE+INSERTs all block rows, nulling the EN-locale fields since they aren't in the update payload. Verified via direct DB query: `{ heroBadge: null, heroTitleLine1: null, faqTitle: null }` for EN after running. Lost prod data; restored by re-running EN populate.

  2. `locale: 'all'` with per-field `{ en, sv }` objects — works correctly. Both locales preserved in a single update. This is what we shipped.

The first workaround is what users are most likely to try (it matches the partial fix in #11402) but it's actively destructive.

Versions

  • payload `3.84.1`
  • @payloadcms/db-postgres `3.84.1`
  • Postgres (Neon)
  • Node 22

Adapter version

@payloadcms/[email protected]

Activity

  1. cafaroo commented on Apr 28, 2026

    @cafaroo
    Author

    Closing — opened in error without the repo owner's authorization. Apologies for the noise.

  2. github-actions commented on May 6, 2026

    @github-actions
    Contributor

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

  3. locked as resolved and limited conversation to collaborators on May 6, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions