Skip to content

fix(ui): copyToLocale should not pass any id's to avoid duplicates #11887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025

Conversation

Bjornnyborg
Copy link
Contributor

What?

Using the Copy To Locale function causes validation errors on content with id fields in postgres, since these should be unique.

key not found: error:valueMustBeUnique
key not found: error:followingFieldsInvalid
[13:11:29] ERROR: There was an error copying data from "en" to "de"
    err: {
      "type": "ValidationError",
      "message": "error:followingFieldsInvalid id",
      "stack":
          ValidationError: error:followingFieldsInvalid id

Why?

In packages/ui/src/utilities/copyDataFromLocale.ts we are passing all data from fromLocaleData including the id fields, which causes duplicates on fields with unique id's like Blocks and Arrays.

How?

To resolve this i implemented a function that recursively remove any id field on the passed data.

Fixes

@genox
Copy link

genox commented Apr 7, 2025

Is there a chance that someone could look into whether this can be merged into one of the next releases? We would love to see a solution to the underlying issue. Thank you in advance!

@Bjornnyborg Bjornnyborg force-pushed the fix/copy-to-locale-remove-ids branch from 909db87 to 08ed1ee Compare April 16, 2025 06:26
@Bjornnyborg
Copy link
Contributor Author

Well, i got desperate - so i have now published the fork including the fix, so if anyone else wants this feature before payload merges it, feel free to use the following in your package.json:
"@payloadcms/ui": "https://github.com/Bjornnyborg/payload/raw/temp/dist/payloadcms-ui-3.34.0.tgz",

@mikkelwf
Copy link
Contributor

This bug basically renders the copy function useless when using block fields.
Can we get this merged in soon please? :)

@jessrynkar
Copy link
Member

@Bjornnyborg thank you for your work on this - and thanks everyone for your patience. I am reviewing now and aim to get the fix merged ASAP

@jessrynkar jessrynkar self-requested a review April 28, 2025 10:28
Copy link
Member

@jessrynkar jessrynkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good and works as expected. I added a test for this issue and a minor change to the removeIds function. Thanks again @Bjornnyborg 🥇

@jessrynkar jessrynkar enabled auto-merge (squash) April 28, 2025 14:24
@jessrynkar jessrynkar merged commit 34ead72 into payloadcms:main Apr 29, 2025
76 checks passed
@genox
Copy link

genox commented Apr 29, 2025

@jessrynkar Thank you for looking into this 👍

Copy link
Contributor

🚀 This is included in version v3.36.0

kendelljoseph pushed a commit that referenced this pull request May 15, 2025
…11887)

### What?
Using the `Copy To Locale` function causes validation errors on content
with `id` fields in postgres, since these should be unique.

```
key not found: error:valueMustBeUnique
key not found: error:followingFieldsInvalid
[13:11:29] ERROR: There was an error copying data from "en" to "de"
    err: {
      "type": "ValidationError",
      "message": "error:followingFieldsInvalid id",
      "stack":
          ValidationError: error:followingFieldsInvalid id
```

### Why?
In `packages/ui/src/utilities/copyDataFromLocale.ts` we are passing all
data from `fromLocaleData` including the `id` fields, which causes
duplicates on fields with unique id's like `Blocks` and `Arrays`.

### How?
To resolve this i implemented a function that recursively remove any
`id` field on the passed data.

### Fixes
- #10684
- https://discord.com/channels/967097582721572934/1351497930984521800

---------

Co-authored-by: Jessica Chowdhury <[email protected]>
kendelljoseph pushed a commit that referenced this pull request May 19, 2025
…11887)

### What?
Using the `Copy To Locale` function causes validation errors on content
with `id` fields in postgres, since these should be unique.

```
key not found: error:valueMustBeUnique
key not found: error:followingFieldsInvalid
[13:11:29] ERROR: There was an error copying data from "en" to "de"
    err: {
      "type": "ValidationError",
      "message": "error:followingFieldsInvalid id",
      "stack":
          ValidationError: error:followingFieldsInvalid id
```

### Why?
In `packages/ui/src/utilities/copyDataFromLocale.ts` we are passing all
data from `fromLocaleData` including the `id` fields, which causes
duplicates on fields with unique id's like `Blocks` and `Arrays`.

### How?
To resolve this i implemented a function that recursively remove any
`id` field on the passed data.

### Fixes
- #10684
- https://discord.com/channels/967097582721572934/1351497930984521800

---------

Co-authored-by: Jessica Chowdhury <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants