不要怂,就是干,撸起袖子干!

Commit e2dad2f9 by Tyler Watson Committed by Sushant

fix(transactions): don't use CLS on manually manged transactions (#8430)

1 parent e695b92c
...@@ -962,7 +962,7 @@ class Sequelize { ...@@ -962,7 +962,7 @@ class Sequelize {
const transaction = new Transaction(this, options); const transaction = new Transaction(this, options);
if (!autoCallback) return transaction.prepareEnvironment().return(transaction); if (!autoCallback) return transaction.prepareEnvironment(false).return(transaction);
// autoCallback provided // autoCallback provided
return Sequelize._clsRun(() => { return Sequelize._clsRun(() => {
......
...@@ -99,9 +99,13 @@ class Transaction { ...@@ -99,9 +99,13 @@ class Transaction {
}); });
} }
prepareEnvironment() { prepareEnvironment(useCLS) {
let connectionPromise; let connectionPromise;
if (typeof useCLS === 'undefined') {
useCLS = true;
}
if (this.parent) { if (this.parent) {
connectionPromise = Utils.Promise.resolve(this.parent.connection); connectionPromise = Utils.Promise.resolve(this.parent.connection);
} else { } else {
...@@ -125,7 +129,7 @@ class Transaction { ...@@ -125,7 +129,7 @@ class Transaction {
throw setupErr; throw setupErr;
})) }))
.tap(() => { .tap(() => {
if (this.sequelize.constructor._cls) { if (useCLS && this.sequelize.constructor._cls) {
this.sequelize.constructor._cls.set('transaction', this); this.sequelize.constructor._cls.set('transaction', this);
} }
return null; return null;
......
...@@ -33,6 +33,17 @@ if (current.dialect.supports.transactions) { ...@@ -33,6 +33,17 @@ if (current.dialect.supports.transactions) {
}); });
describe('context', () => { describe('context', () => {
it('does not use continuation storage on manually managed transactions', function() {
const self = this;
return Sequelize._clsRun(() => {
return this.sequelize.transaction().then(transaction => {
expect(self.ns.get('transaction')).to.be.undefined;
return transaction.rollback();
});
});
});
it('supports several concurrent transactions', function() { it('supports several concurrent transactions', function() {
let t1id, t2id; let t1id, t2id;
const self = this; const self = this;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!