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

Commit e26f62f2 by Andreas Lind Committed by Sushant

fix(transaction): prevent rollback without connection (#9889)

1 parent e3bba447
...@@ -85,6 +85,10 @@ class Transaction { ...@@ -85,6 +85,10 @@ class Transaction {
return Utils.Promise.reject(new Error('Transaction cannot be rolled back because it has been finished with state: ' + this.finished)); return Utils.Promise.reject(new Error('Transaction cannot be rolled back because it has been finished with state: ' + this.finished));
} }
if (!this.connection) {
return Promise.reject(new Error('Transaction cannot be rolled back because it never started'));
}
this._clearCls(); this._clearCls();
return this return this
......
...@@ -161,6 +161,16 @@ if (current.dialect.supports.transactions) { ...@@ -161,6 +161,16 @@ if (current.dialect.supports.transactions) {
).to.eventually.be.rejected; ).to.eventually.be.rejected;
}); });
it('should not rollback if connection was not acquired', function() {
this.sinon.stub(this.sequelize.connectionManager, '_connect')
.returns(new Support.Sequelize.Promise(() => {}));
const transaction = new Transaction(this.sequelize);
return expect(transaction.rollback())
.to.eventually.be.rejectedWith('Transaction cannot be rolled back because it never started');
});
it('does not allow queries immediatly after rollback call', function() { it('does not allow queries immediatly after rollback call', function() {
const self = this; const self = this;
return expect( return expect(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!