Getting unhandled promise reject on model.bulkCreate method following upsert flow #16860
Labels
pending-approval
Bug reports that have not been verified yet, or feature requests that have not been accepted yet
type: bug
Issue Creation Checklist
Bug Description
I was working on implementing bulk upsertion for some work. While doing bulkUpsert I am getting unhandledPromiseRejection
error although I have handled errors in my code using try-catch.
Reproducible Example
Code-Block:
public static async upsertPatientRecords(patientRecords: any, log: log4js.Logger) { try { CustomerTable.bulkCreate(custonerRecords, { updateOnDuplicate: columnsToUpdate }); } catch (error) { log.info('Error - ' + error); throw error; }
Error Log
`{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "SequelizeDatabaseError: ON CONFLICT DO UPDATE command cannot affect row a second time",
"reason": {
"errorType": "SequelizeDatabaseError",
"errorMessage": "ON CONFLICT DO UPDATE command cannot affect row a second time",
"name": "SequelizeDatabaseError",
"parent": {
"errorType": "error",
"errorMessage": "ON CONFLICT DO UPDATE command cannot affect row a second time",
"code": "21000",
"length": 239,
"name": "error",
"severity": "ERROR",
"hint": "Ensure that no rows proposed for insertion within the same command have duplicate constrained values.",
"file": "nodeModifyTable.c",
"line": "2179",
"routine": "ExecOnConflictUpdate",
"sql": "INSERT INTO "schema_name"."customer_records" ("practice","name","patient_chart_number","enterprise_id") VALUES ('My practice', 'mary joseph', 'HHHHH', 1231 ) ON CONFLICT ("patient_chart_number","enterprise_id") DO UPDATE SET "practice"=EXCLUDED."practice","name"=EXCLUDED."name", RETURNING "practice","name","patient_chart_number";",
"parameters": {
},
"stack": [
"Error",
" at Query.run (/var/task/node_modules/sequelize/lib/dialects/postgres/query.js:50:25)",
" at /var/task/node_modules/sequelize/lib/sequelize.js:315:28",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async PostgresQueryInterface.bulkInsert (/var/task/node_modules/sequelize/lib/dialects/abstract/query-interface.js:346:21)",
" at async recursiveBulkCreate (/var/task/node_modules/sequelize/lib/model.js:1697:25)",
" at async Patient.bulkCreate (/var/task/node_modules/sequelize/lib/model.js:1786:12)"
]
},
"promise": {
}`
What do you expect to happen?
If error catching has been handled, it shouldn't show UnhandledPromiseRejection error.
What is actually happening?
Getting unhandled promise rejection error on execution of my script.
I have implemented bulkCreate using upsert logic in my project.
Although error catching has been implemented using try-catch, still it says UnhandledPromiseRejection
Environment
Would you be willing to resolve this issue by submitting a Pull Request?
No, I have the time and I know how to start.
Yes, I have the time but I will need guidance.
No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: