payloadcms / payload

The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
https://payloadcms.com
MIT License
21.16k stars 1.27k forks source link

bug(db-postgres): Duplicated ID error when duplicate array/block includes array/block. #6583

Open SimYunSup opened 1 month ago

SimYunSup commented 1 month ago

Link to reproduction

https://github.com/SimYunSup/example-list/tree/payload/bug-postgres-nested-id

Describe the Bug

Duplicated ID error when duplicate Array/Block that includes Array/Block.

Reported Bug ```text [16:56:40] ERROR (payload): TypeError: Cannot read properties of undefined (reading 'nested_blocks_just_text_pkey') at upsertRow (D:\GithubProject\example-list\node_modules\.pnpm\@payloadcms+db-postgres@0.8.4_@types+react@18.3.3_payload@2.18.3_@swc+helpers@0.5.11_@types+r_utjmzo3j7ceboprn5scvypgwvm\node_modules\@payloadcms\db-postgres\src\upsertRow\index.ts:318:57) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.updateOne (D:\GithubProject\example-list\node_modules\.pnpm\@payloadcms+db-postgres@0.8.4_@types+react@18.3.3_payload@2.18.3_@swc+helpers@0.5.11_@types+r_utjmzo3j7ceboprn5scvypgwvm\node_modules\@payloadcms\db-postgres\src\update.ts:44:18) at async updateByID (D:\GithubProject\example-list\node_modules\.pnpm\payload@2.18.3_@swc+helpers@0.5.11_@types+react@18.3.3_esbuild@0.19.12_typescript@5.4.5_webpa_w2wwwoljy4lt2mm3kbswof65oi\node_modules\payload\src\collections\operations\updateByID.ts:269:16) at async updateByIDHandler (D:\GithubProject\example-list\node_modules\.pnpm\payload@2.18.3_@swc+helpers@0.5.11_@types+react@18.3.3_esbuild@0.19.12_typescript@5.4.5_webpa_w2wwwoljy4lt2mm3kbswof65oi\node_modules\payload\src\collections\requestHandlers\updateByID.ts:43:17) ```

To Reproduce

  1. Create a Nested collection item.
  2. Fill in the fields in one of the order listed below.
    1. Block in Block
      • Create nested-block in blocks
      • Create just-text in nested
      • Fill title(optional)
    2. Array in Block
      • Create nested-array in blocks
      • Create item in nested
      • Fill title(optional)
    3. Block in Array
      • Create item in nestedArrayBlocks
      • Create just-text in nested
      • Fill title(optional)
    4. Block in Block
      • Create item in nestedArrayArray
      • Create item in nested
      • Fill title(optional)
  3. Duplicates any top-level Block or Array.
  4. When you submit, you should get an error.

I think It must replace nested ID.

And I think Same in 3.0.0-beta.39 because DUPLICATE_ROW has same logic.

Payload Version

2.18.3

Adapters and Plugins

@payloadcms/db-postgres@0.8.4, @payloadcms/bundler-webpack@1.0.6

siobahnschuck commented 1 month ago

Seeing the same issue with 3.0.0-beta.36 as well.