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

Commit 54797225 by Mick Hansen

Merge pull request #5428 from jharting/more-debug-when-transaction-finished

Log which query tried to run on a finished transaction
2 parents 34b964bb 0d0aad6a
...@@ -789,7 +789,9 @@ Sequelize.prototype.query = function(sql, options) { ...@@ -789,7 +789,9 @@ Sequelize.prototype.query = function(sql, options) {
} }
if (options.transaction && options.transaction.finished) { if (options.transaction && options.transaction.finished) {
return Promise.reject(new Error(options.transaction.finished+' has been called on this transaction('+options.transaction.id+'), you can no longer use it')); var error = new Error(options.transaction.finished+' has been called on this transaction('+options.transaction.id+'), you can no longer use it. (The rejected query is attached as the \'sql\' property of this error)');
error.sql = sql;
return Promise.reject(error);
} }
if (this.test.$trackRunningQueries) { if (this.test.$trackRunningQueries) {
......
...@@ -117,15 +117,17 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -117,15 +117,17 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
it('does not allow queries after commit', function() { it('does not allow queries after commit', function() {
var self = this; var self = this;
return expect( return this.sequelize.transaction().then(function(t) {
this.sequelize.transaction().then(function(t) { return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true}).then(function() {
return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true}).then(function() { return t.commit();
return t.commit(); }).then(function() {
}).then(function() { return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true});
return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true}); });
}); }).throw(new Error('Expected error not thrown'))
}) .catch (function (err) {
).to.eventually.be.rejected; expect (err.message).to.match(/commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/);
expect (err.sql).to.equal('SELECT 1+1');
});
}); });
it('does not allow queries immediatly after commit call', function() { it('does not allow queries immediatly after commit call', function() {
...@@ -135,7 +137,12 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -135,7 +137,12 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true}).then(function() { return self.sequelize.query('SELECT 1+1', {transaction: t, raw: true}).then(function() {
return Promise.join( return Promise.join(
expect(t.commit()).to.eventually.be.fulfilled, expect(t.commit()).to.eventually.be.fulfilled,
expect(self.sequelize.query('SELECT 1+1', {transaction: t, raw: true})).to.eventually.be.rejectedWith(/commit has been called on this transaction\([^)]+\), you can no longer use it/) self.sequelize.query('SELECT 1+1', {transaction: t, raw: true})
.throw(new Error('Expected error not thrown'))
.catch (function (err) {
expect (err.message).to.match(/commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/);
expect (err.sql).to.equal('SELECT 1+1');
})
); );
}); });
}) })
...@@ -161,7 +168,12 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -161,7 +168,12 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
this.sequelize.transaction().then(function(t) { this.sequelize.transaction().then(function(t) {
return Promise.join( return Promise.join(
expect(t.rollback()).to.eventually.be.fulfilled, expect(t.rollback()).to.eventually.be.fulfilled,
expect(self.sequelize.query('SELECT 1+1', {transaction: t, raw: true})).to.eventually.be.rejectedWith(/rollback has been called on this transaction\([^)]+\), you can no longer use it/) self.sequelize.query('SELECT 1+1', {transaction: t, raw: true})
.throw(new Error('Expected error not thrown'))
.catch (function (err) {
expect (err.message).to.match(/rollback has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/);
expect (err.sql).to.equal('SELECT 1+1');
})
); );
}) })
).to.eventually.be.fulfilled; ).to.eventually.be.fulfilled;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!