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

Commit 465b9768 by Mick Hansen

fix(transactions): reject queries using a transaction that has already finished …

…(committed or rolled back), closes #2082
1 parent 95977e43
......@@ -602,6 +602,10 @@ module.exports = (function() {
type: (sql.toLowerCase().indexOf('select') === 0) ? QueryTypes.SELECT : false
});
if (options.transaction && options.transaction.finished) {
return Promise.reject(options.transaction.finished+' has been called on this transaction, you can no longer use it');
}
return Promise.resolve(
options.transaction ? options.transaction.connection : self.connectionManager.getConnection(options)
).then(function (connection) {
......
......@@ -82,6 +82,7 @@ Transaction.prototype.commit = function() {
.getQueryInterface()
.commitTransaction(this, this.options)
.finally(function() {
self.finished = 'commit';
if (!self.options.transaction) {
self.cleanup();
}
......@@ -102,6 +103,7 @@ Transaction.prototype.rollback = function() {
.getQueryInterface()
.rollbackTransaction(this, this.options)
.finally(function() {
self.finished = 'rollback';
if (!self.options.transaction) {
self.cleanup();
}
......
......@@ -58,6 +58,32 @@ describe(Support.getTestDialectTeaser("Transaction"), function () {
});
});
it('does not allow queries after commit', function () {
var self = this;
return expect(
this.sequelize.transaction().then(function (t) {
return self.sequelize.query("SELECT 1+1", null, {transaction: t, raw: true}).then(function () {
return t.commit();
}).then(function () {
return self.sequelize.query("SELECT 1+1", null, {transaction: t, raw: true});
});
})
).to.eventually.be.rejected;
});
it('does not allow queries after rollback', function () {
var self = this;
return expect(
this.sequelize.transaction().then(function (t) {
return self.sequelize.query("SELECT 1+1", null, {transaction: t, raw: true}).then(function () {
return t.commit();
}).then(function () {
return self.sequelize.query("SELECT 1+1", null, {transaction: t, raw: true});
});
})
).to.eventually.be.rejected;
});
if (current.dialect.supports.lock) {
describe('row locking', function () {
this.timeout(10000);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!