Repository navigation
Closed
Description
What are you doing?
I'm trying to add Sequelize transactions to my Express app, but I'm unsuccessful. I'm using async/await across the app, and I've created the namespace using the 'cls' package as instructed on the docs for Sequelize transactions. I' am using bluebird promises and async/await polyfills so I dont need to use 'cls-hooked'.
import cls from 'continuation-local-storage'
const ns = cls.createNamespace('default')
Sequelize.useCLS(ns);My middleware
import models from '../models'
import cls from 'continuation-local-storage'
export default async (req, res, next) => {
const ns = cls.getNamespace('default')
models.Sequelize.useCLS(ns)
return models.sequelize.transaction(async () => next())
}What do you expect to happen?
I wanted all db operations in same transaction.
What is actually happening?
The result is that I get the transaction, but only around the first DB operation. Everything after that is ignored.
Listening on port 3001
Executing (7a95e171-2711-44e1-ad2b-33985212d4cf): START TRANSACTION;
Executing (7a95e171-2711-44e1-ad2b-33985212d4cf): SELECT `id`, `name`, `email`, `laboratoryId`, `passwordDigest`, `createdAt`, `updatedAt`, `deletedAt`, `version`, `LaboratoryId` FROM `Users` AS `User` WHERE ((`User`.`deletedAt` > '2018-03-21 18:50:55' OR `User`.`deletedAt` IS NULL) AND `User`.`id` = 1);
Executing (7a95e171-2711-44e1-ad2b-33985212d4cf): COMMIT;
Executing (default): SELECT `id`, `name`, `createdAt`, `updatedAt`, `deletedAt`, `version` FROM `Laboratories` AS `Laboratory` WHERE ((`Laboratory`.`deletedAt` > '2018-03-21 18:50:55' OR `Laboratory`.`deletedAt` IS NULL) AND `Laboratory`.`id` = 1);
Executing (default): SELECT `id`, `name`, `email`, `laboratoryId`, `passwordDigest`, `createdAt`, `updatedAt`, `deletedAt`, `version`, `LaboratoryId` FROM `Users` AS `User` WHERE ((`User`.`deletedAt` > '2018-03-21 18:50:55' OR `User`.`deletedAt` IS NULL) AND `User`.`id` = 1);
Executing (default): INSERT INTO `Laboratories` (`id`,`name`,`createdAt`,`updatedAt`,`version`) VALUES (DEFAULT,'lab611222121','2018-03-21 18:50:55','2018-03-21 18:50:55',0);
POST /api/laboratories?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MX0.BIAiSEdfYaeKa7850IDYhrRQRroTZsPXEz1ZNxgQ3eE 201 293.986 ms - 121
Dialect: mysql
Dialect version: XXX
Database version: mysqld Ver 5.7.21 for osx10.13 on x86_64 (Homebrew)
Sequelize version: 4.37.3
Tested with latest release: No (If yes, specify that version)
Metadata
Metadata
Assignees
Labels
No labels
Activity
sushantdhiman commentedon Mar 22, 2018
This is because
retry as promisedis not using patched Promise, #9071Can you try with any version before
4.33.4?danielgatis commentedon Mar 22, 2018
Same problem
danielgatis commentedon Mar 23, 2018
IMHO. I don't think this issue is a question.
sushantdhiman commentedon May 25, 2018
Fixed by #9473