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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bjornnyborg
Copy link

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
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",

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.

2 participants