sequelize / sequelize/sequelize

bulkCreate with included model and individualHooks: true creates included models twice

Open
#13,667 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: hooks type: bug
Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

Issue Creation Checklist

Bug Description

SSCCE

I couldn't get the https://github.com/papb/sequelize-sscce to run, so I created my own repo:

Here is the link to the SSCCE for this issue: link

What do you expect to happen?

When calling bulkCreate on a model with include (I only tested hasMany association) and individualHooks: true, I expect included models to be created once.

What is actually happening?

As demonstrated in the SSCCE, a ValidationError is thrown because sequelize tries to create the included models twice with the same id.

Environment
  • Sequelize version: 6.9.0
  • Node.js version: 14.18.0

Bug Report Checklist

How does this problem relate to dialects?
  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using postgres, with connector library version pg@8.7.1 and database version 13.4
Would you be willing to resolve this issue by submitting a Pull Request?
  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked SSCCE repository with Sequelize 6.9.0, Node.js 14.18.0, PostgreSQL, and individualHooks enabled. Trace the bulkCreate call with its included hasMany model and add a regression test showing that the included records are created once. Done means the duplicate creation and resulting ValidationError no longer occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, postgresql, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.