Closed radoslaw-sz closed 1 month ago
Hello! Can you share the code snippet that's causing the error to occur?
hi @shahednasser - thank you for your response. To be honest, I am not sure which part of my code executes it as there are these workflows, steps etc.
To reproduce this issue, it is enough to just follow the instruction here: https://docs.medusajs.com/v2/resources/recipes/digital-products/examples/standard, but instead of having hasMany
just go with hasOne
in digitalProduct
.
Can you share the point in the recipe where you started running into this error? Also can you share the full error message?
Regarding recipe - when we have creation of data models here: https://docs.medusajs.com/v2/resources/recipes/digital-products/examples/standard#create-data-models it is enough to change
medias: model.hasMany(() => DigitalProductMedia, {
mappedBy: "digitalProduct",
}),
to
```ts
medias: model.hasOne(() => DigitalProductMedia, {
mappedBy: "digitalProduct",
}),
This of course causes that in a lot of places the update is needed, but after alignments, it is impossible to add digital product via UI.
Here is the full error (I just change digital_product_medias
to digital_product_reference
as mentioned in the first message):
error: insert into "public"."digital_product_reference" ("id", "type", "licence_key", "digital_product_id", "created_at", "updated_at") values ('01J67TCZJTPXFGM22Y9VFWEXJ3', 'licence_key', 'LICENCE_KEY-123', '01J67TCZJTPQB9YWGTSZ73VP1Q', '2024-08-26T17:05:38.907Z', '2024-08-26T17:05:38.907Z', '01J67TCZJTPQB9YWGTSZ73VP1Q') returning "id", "created_at", "updated_at" - INSERT has more expressions than target columns
{
message: `insert into "public"."digital_product_reference" ("id", "type", "licence_key", "digital_product_id", "created_at", "updated_at") values ('01J67TCZJTPXFGM22Y9VFWEXJ3', 'licence_key', 'LICENCE_KEY-123', '01J67TCZJTPQB9YWGTSZ73VP1Q', '2024-08-26T17:05:38.907Z', '2024-08-26T17:05:38.907Z', '01J67TCZJTPQB9YWGTSZ73VP1Q') returning "id", "created_at", "updated_at" - INSERT has more expressions than target columns`,
name: 'SyntaxErrorException',
stack: `SyntaxErrorException: insert into "public"."digital_product_reference" ("id", "type", "licence_key", "digital_product_id", "created_at", "updated_at") values ('01J67TCZJTPXFGM22Y9VFWEXJ3', 'licence_key', 'LICENCE_KEY-123', '01J67TCZJTPQB9YWGTSZ73VP1Q', '2024-08-26T17:05:38.907Z', '2024-08-26T17:05:38.907Z', '01J67TCZJTPQB9YWGTSZ73VP1Q') returning "id", "created_at", "updated_at" - INSERT has more expressions than target columns\n` +
' at PostgreSqlExceptionConverter.convertException (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:32:24)\n' +
' at PostgreSqlDriver.convertException (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:201:54)\n' +
' at /home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:205:24\n' +
' at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async PostgreSqlDriver.nativeInsertMany (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/knex/AbstractSqlDriver.js:302:21)\n' +
' at async ChangeSetPersister.persistNewEntity (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:88:21)\n' +
' at async ChangeSetPersister.executeInserts (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:32:13)\n' +
' at async ChangeSetPersister.runForEachSchema (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:71:13)\n' +
' at async UnitOfWork.commitCreateChangeSets (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:741:9)\n' +
' at async UnitOfWork.persistToDatabase (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:705:13)\n' +
' at async UnitOfWork.doCommit (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:301:17)\n' +
' at async UnitOfWork.commit (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:268:13)\n' +
' at async SqlEntityManager.flush (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/EntityManager.js:1122:9)\n' +
' at async fork.getConnection.transactional (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/core/EntityManager.js:775:17)\n' +
' at async PostgreSqlConnection.transactional (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@mikro-orm/knex/AbstractSqlConnection.js:36:25)\n' +
' at async transactionWrapper (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/dal/utils.ts:32:10)\n' +
' at async MikroOrmAbstractBaseRepository_.transaction (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/dal/mikro-orm/mikro-orm-repository.ts:74:12)\n' +
' at async AbstractService_.descriptor.value (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/modules-sdk/decorators/inject-transaction-manager.ts:44:14)\n' +
' at async DigitalProductModuleService.methodImplementation (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/modules-sdk/medusa-service.ts:194:26)\n' +
' at async Proxy.<anonymous> (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/orchestration/src/workflow/local-workflow.ts:124:20)\n' +
' at async Object.async.digital_product.digital_product (/home/ubuntu/rsc/medusa/app-medusa/src/workflows/create-digital-product/steps/create-digital-product.ts:22:28)\n' +
' at async Object.invoke (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:55:52)\n' +
' at async DistributedTransaction.handler (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/orchestration/src/workflow/workflow-manager.ts:214:16)\n' +
' at async Promise.allSettled (index 0)\n' +
' at async promiseAll (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/common/promise-all.ts:23:18)\n' +
' at async TransactionOrchestrator.executeNext (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:848:7)\n' +
' at async TransactionOrchestrator.resume (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:893:5)\n' +
' at async LocalWorkflow.run (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/orchestration/src/workflow/local-workflow.ts:365:5)\n' +
' at async originalExecution (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:102:25)\n' +
' at async LocalWorkflow.newRun [as run] (/home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:186:12)\n' +
' at async POST (/home/ubuntu/rsc/medusa/app-medusa/src/api/admin/digital-products/route.ts:58:22)\n' +
' at async /home/ubuntu/rsc/medusa/app-medusa/node_modules/@medusajs/utils/src/common/wrap-handler.ts:17:14\n' +
'\n' +
`previous error: insert into "public"."digital_product_reference" ("id", "type", "licence_key", "digital_product_id", "created_at", "updated_at") values ('01J67TCZJTPXFGM22Y9VFWEXJ3', 'licence_key', 'LICENCE_KEY-123', '01J67TCZJTPQB9YWGTSZ73VP1Q', '2024-08-26T17:05:38.907Z', '2024-08-26T17:05:38.907Z', '01J67TCZJTPQB9YWGTSZ73VP1Q') returning "id", "created_at", "updated_at" - INSERT has more expressions than target columns\n` +
' at Parser.parseErrorMessage (/home/ubuntu/rsc/medusa/app-medusa/node_modules/pg-protocol/src/parser.ts:369:69)\n' +
' at Parser.handlePacket (/home/ubuntu/rsc/medusa/app-medusa/node_modules/pg-protocol/src/parser.ts:188:21)\n' +
' at Parser.parse (/home/ubuntu/rsc/medusa/app-medusa/node_modules/pg-protocol/src/parser.ts:103:30)\n' +
' at Socket.<anonymous> (/home/ubuntu/rsc/medusa/app-medusa/node_modules/pg-protocol/src/index.ts:7:48)\n' +
' at Socket.emit (node:events:519:28)\n' +
' at Socket.emit (node:domain:488:12)\n' +
' at addChunk (node:internal/streams/readable:559:12)\n' +
' at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n' +
' at Socket.Readable.push (node:internal/streams/readable:390:5)\n' +
' at TCP.onStreamRead (node:internal/stream_base_commons:190:23)\n' +
' at TCP.callbackTrampoline (node:internal/async_hooks:130:17)',
length: 117,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '288',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'analyze.c',
line: '1026',
routine: 'transformInsertRow'
}
Looking at the error stack trace, the error occurs at src/workflows/create-digital-product/steps/create-digital-product.ts
line 22, and the workflow is executed at src/api/admin/digital-products/route.ts:58:22
Can you share the code in both files? Also the request you're making to the create digital product API route (with the request body)?
hi @shahednasser - it looks like it is being handled :)
I am struggling with the problem for already couple of days and after a lot of debugging, unfortunately my current suspcious that there is some kind of the bug.
I am following instruction: https://docs.medusajs.com/v2/resources/recipes/digital-products/examples/standard
But in my scenario, I would like to have only single relationship between
digitalProduct
and its child (in my case it is calleddigitalProductReference
instead of media as in example). Here are my models:And when I am trying to create entry in database, here is the error:
The example works properly with [array] of digitalProductReference (or digitalProductMedias) in
mappedBy
, but it fails as above in case ofmodel.hasOne
relationship.for analysis purposes, here are the examples of
changeSets
which are going into database: working example:not working example:
As you can see, in not working example, there is additional field
digitalProduct
inpayload
which probably causes errors as there are more columns than in database.