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

Commit f950409b by Mick Hansen

Merge branch 'fix-transactions' of https://github.com/BridgeAR/sequelize into Br…

…idgeAR-fix-transactions

Conflicts:
	changelog.md
2 parents 08e8c92d ece0d9ef
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- [BUG] Fix addIndexQuery error when the model has a schema - [BUG] Fix addIndexQuery error when the model has a schema
- [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730) - [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
- [BUG] Fix bulkCreate: do not insert NULL for undefined values [3729](https://github.com/sequelize/sequelize/pull/3729) - [BUG] Fix bulkCreate: do not insert NULL for undefined values [3729](https://github.com/sequelize/sequelize/pull/3729)
- [BUG] Fix API doc generation - [BUG] Fix trying to roll back a comitted transaction if an error occured while comitting resulting in an unhandled rejection [3726](https://github.com/sequelize/sequelize/pull/3726)
#### Backwards compatibility changes #### Backwards compatibility changes
- The error that is thrown when a column is declared to be an enum but without any values used to "Values for ENUM haven't been defined" and is now "Values for ENUM have not been defined". - The error that is thrown when a column is declared to be an enum but without any values used to "Values for ENUM haven't been defined" and is now "Values for ENUM have not been defined".
......
...@@ -1149,9 +1149,13 @@ module.exports = (function() { ...@@ -1149,9 +1149,13 @@ module.exports = (function() {
}); });
}); });
}).catch(function(err) { }).catch(function(err) {
transaction.rollback().finally(function () { if (transaction.finished === 'commit') {
reject(err); reject(err);
}); } else {
transaction.rollback().finally(function () {
reject(err);
});
}
}); });
}; };
......
...@@ -73,6 +73,30 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -73,6 +73,30 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
expect(t.finished).to.be.equal('rollback'); expect(t.finished).to.be.equal('rollback');
}); });
}); });
if (dialect === 'postgres' || dialect === 'mssql') {
it('do not rollback if already committed', function() {
var SumSumSum = this.sequelize.define('transaction', {
value: {
type: Support.Sequelize.DECIMAL(10, 3),
field: 'value'
}
})
, transTest = function (val) {
return self.sequelize.transaction({isolationLevel: 'SERIALIZABLE'}, function(t) {
return SumSumSum.sum('value', {transaction: t}).then(function (balance) {
return SumSumSum.create({value: -val}, {transaction: t});
});
});
}
, self = this;
return SumSumSum.sync({force: true}).then(function () {
return (expect(Promise.join(transTest(80), transTest(80))).to.eventually.be.rejectedWith('could not serialize access due to read/write dependencies among transactions'));
});
});
}
}); });
it('does not allow queries after commit', function() { it('does not allow queries after commit', function() {
......
...@@ -17,7 +17,12 @@ chai.config.includeStack = true; ...@@ -17,7 +17,12 @@ chai.config.includeStack = true;
chai.should(); chai.should();
// Make sure errors get thrown when testing // Make sure errors get thrown when testing
process.on('uncaughtException', function(e, promise) {
console.error('An unhandled exception occured:');
throw e;
});
Sequelize.Promise.onPossiblyUnhandledRejection(function(e, promise) { Sequelize.Promise.onPossiblyUnhandledRejection(function(e, promise) {
console.error('An unhandled rejection occured:');
throw e; throw e;
}); });
Sequelize.Promise.longStackTraces(); Sequelize.Promise.longStackTraces();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!