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
24.88k stars 1.58k forks source link

Entry duplication not possible if entry has blocks across multiple locales #7988

Closed tiago-meireles closed 1 month ago

tiago-meireles commented 2 months ago

Link to reproduction

No response

Environment Info

Payload: beta.96
Node.js: 20 LTS
Next.js: 15.0.0-canary.104

Describe the Bug

It's not possible to duplicate multiple times in the same collection entry if:

  1. Entry has blocks
  2. Those entry blocks exist across multiple locales

This works ok when we try to duplicate the entry the first time. On the second duplication try, a constraint is triggered (ERROR: duplicate key value violates unique constraint) for the id in the database table that has the relationship between the entry and the block (for example: pages_blocks_media)

Reproduction Steps

  1. Use the demo beta application
  2. Configure multiple locales ('en' and 'es')
  3. Create a page and add the Media Block in both the en and es locales
  4. Try to duplicate the page (This should work ok)
  5. Try to duplicate the page a second time (This should fail with the id constraint)

Adapters and Plugins

No response

jmikrut commented 2 months ago

We can solve this one pretty quickly by using the before duplicate hook! Thanks for bringing this up

jmikrut commented 1 month ago

This has been fixed!

github-actions[bot] commented 1 month ago

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