Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting unhandled promise reject on model.bulkCreate method following upsert flow #16860

Closed
shahabali1993 opened this issue Dec 11, 2023 · 1 comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug

Comments

@shahabali1993
Copy link

shahabali1993 commented Dec 11, 2023

Issue Creation Checklist

  • [Y] I understand that my issue will be automatically closed if I don't fill in the requested information
  • [Y] I have read the contribution guidelines

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": {

},
"stack": [
  "Runtime.UnhandledPromiseRejection: SequelizeDatabaseError: ON CONFLICT DO UPDATE command cannot affect row a second time",
  "    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)",
  "    at process.emit (node:events:517:28)",
  "    at emit (node:internal/process/promises:149:20)",
  "    at processPromiseRejections (node:internal/process/promises:283:27)",
  "    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"
]

}`

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

  • Sequelize version: 6.33.0
  • Node.js version: 18.17.1
  • If TypeScript related: TypeScript version: 5.2.2
  • Database & Version: Postgres & 14.1
  • Connector library & Version: pg & 8.11.3

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.

@shahabali1993 shahabali1993 added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Dec 11, 2023
@ephys
Copy link
Member

ephys commented Dec 13, 2023

You're not awaiting the promise returned by bulkCreate, so the error is never caught by the try-catch

@ephys ephys closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug
Projects
None yet
Development

No branches or pull requests

2 participants