Skip to content

fix(ui): copyToLocale should not pass id in data, throws error in postgres - #11402

Merged
JarrodMFlesch merged 1 commit into
mainfrom
fix/copy-to-locale-id
Feb 28, 2025
Merged

JarrodMFlesch merged 1 commit into
mainfrom
fix/copy-to-locale-id

Conversation

@JessRynkar

Copy link
Copy Markdown
Member

What?

Using the Copy To Locale function with Postgres throws an error related to the id field:

[15:15:41] 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 fromLocaleData to updateByID on Line 314.

This data contains an id and causes an error to be thrown during the update process - only when using Postgres.

How?

To resolve we needed to remove id from the fromLocaleData before updating the document.

Closes #11309

@JarrodMFlesch
JarrodMFlesch merged commit 428c133 into main Feb 28, 2025
@JarrodMFlesch
JarrodMFlesch deleted the fix/copy-to-locale-id branch February 28, 2025 17:06
@github-actions

github-actions Bot commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.26.0

@Bjornnyborg

Copy link
Copy Markdown
Contributor

@JessChowdhury I am afraid that i still experience the error in the latest version.

Full error:

    err: {
      "type": "ValidationError",
      "message": "error:followingFieldsInvalid id",
      "stack":
          ValidationError: error:followingFieldsInvalid id
              at upsertRow (webpack-internal:///(rsc)/./node_modules/@payloadcms/drizzle/dist/upsertRow/index.js:364:19)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async Object.updateOne (webpack-internal:///(rsc)/./node_modules/@payloadcms/drizzle/dist/updateOne.js:59:20)
              at async updateDocument (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/utilities/update.js:211:18)
              at async updateByIDOperation (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/updateByID.js:112:22)
              at async copyDataFromLocale (webpack-internal:///(rsc)/./node_modules/@payloadcms/ui/dist/utilities/copyDataFromLocale.js:218:8)
              at async copyDataFromLocaleHandler (webpack-internal:///(rsc)/./node_modules/@payloadcms/ui/dist/utilities/copyDataFromLocale.js:124:12)
              at async C:\work\thirdspace\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:447:2357
              at async handleAction (C:\work\thirdspace\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:446:23434)
              at async renderToHTMLOrFlightImpl (C:\work\thirdspace\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:452:26466)
              at async doRender (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:1650:34)
              at async DevServer.renderToResponseWithComponentsImpl (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:1915:28)
              at async DevServer.renderPageComponent (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:2393:24)
              at async DevServer.renderToResponseImpl (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:2430:32)
              at async DevServer.pipeImpl (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:1003:25)
              at async NextNodeServer.handleCatchallRenderRequest (C:\work\thirdspace\node_modules\next\dist\server\next-server.js:304:17)
              at async DevServer.handleRequestImpl (C:\work\thirdspace\node_modules\next\dist\server\base-server.js:895:17)
              at async C:\work\thirdspace\node_modules\next\dist\server\dev\next-dev-server.js:371:20
              at async Span.traceAsyncFn (C:\work\thirdspace\node_modules\next\dist\trace\trace.js:157:20)
              at async DevServer.handleRequest (C:\work\thirdspace\node_modules\next\dist\server\dev\next-dev-server.js:368:24)
              at async invokeRender (C:\work\thirdspace\node_modules\next\dist\server\lib\router-server.js:234:21)
              at async handleRequest (C:\work\thirdspace\node_modules\next\dist\server\lib\router-server.js:422:24)
              at async requestHandlerImpl (C:\work\thirdspace\node_modules\next\dist\server\lib\router-server.js:446:13)
              at async Server.requestListener (C:\work\thirdspace\node_modules\next\dist\server\lib\start-server.js:158:13)
      "data": {
        "id": 2,
        "errors": [
          {
            "message": "error:valueMustBeUnique",
            "path": "id"
          }
        ]
      },
      "isOperational": true,
      "isPublic": false,
      "status": 400,
      "name": "ValidationError"
    }

@jorgebef

jorgebef commented Mar 23, 2025 •

Copy link
Copy Markdown

I am also experiencing the same issue in the latest version at the time of writing 3.29.0.
Additionally, I have checked the postgres logs and this is what I found:

2025-03-23 20:34:59.771 UTC [2229624] ERROR:  duplicate key value violates unique constraint "pages_blocks_content_grid_cell_array_pkey"
2025-03-23 20:34:59.771 UTC [2229624] DETAIL:  Key (id)=(67d5df73466d9a11798fe71b) already exists.
2025-03-23 20:34:59.771 UTC [2229624] STATEMENT:  insert into "pages_blocks_content_grid_cell_array" ("_order", "_parent_id", "_locale", "id", "size", "align") values ($1, $2, $3, $4, $5, $6), ($7, $8, $9, $10, $11, $12), ($13, $14, $15, $16, $17, $18), ($19, $20, $21, $22, $23, $24), ($25, $26, $27, $28, $29, $30), ($31, $32, $33, $34, $35, $36), ($37, $38, $39, $40, $41, $42), ($43, $44, $45, $46, $47, $48) returning "_order", "_parent_id", "_locale", "id", "size", "align"

Specifically, the id 67d5df73466d9a11798fe71b is from the origin locale, so I believe that the id is still being brought from the original locale. I've confirmed this by attempting to copy from a specific locale to various different locales, and the error is the exact same, with the same id.

Edit:
I've continued testing and found that the issue appears only when the origin locale contains any block that has an array type field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error copying data from locale

4 participants