sequelize / sequelize/sequelize

bulkCreate + options.returning on a table with hasTrigger enabled does not work

Open
#7,075 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What you are doing?

var Task = sequelize.define('task', {
    title: Sequelize.STRING,
    rating: { type: Sequelize.STRING, defaultValue: 3 }
}, {
    hasTrigger: true
});

Task.bulkCreate([{
    title: "Fix bug",
    rating: "5"
}, {
    title: "Write documentation",
    rating: "1"
}], {
    returning: true
});
// Error happens

What do you expect to happen?

Promise should return a list of successfully inserted instances with resulting values of autoIncrement attributes.

What is actually happening?

Unhandled rejection SequelizeDatabaseError: The target table '%TABLE_NAME_HERE%' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.

Dialect: mssql
Database version: SQL Server 2014
Sequelize version: 3.24.3

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

Begin at Task.bulkCreate with returning: true in the MSSQL path and trace how enabled triggers affect the generated INSERT and OUTPUT behavior. Reproduce the SQL Server 2014 error with the model shown, then add coverage for the case; done means bulkCreate resolves with inserted instances containing their resulting auto-increment values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, sql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.