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

Commit 7c9d1d7b by Mick Hansen

Merge pull request #3730 from BridgeAR/fix-crash

Fix sqlite crash while parsing unique constraint errors. Fixes #3546 #3409
2 parents 2161b3f5 83558e4d
# Next
- [BUG] fix showIndexQuery so appropriate indexes are returned when a schema is used
- [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)
# 2.1.3
- [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
......
......@@ -215,15 +215,17 @@ module.exports = (function() {
fields.forEach(function(field) {
errors.push(new sequelizeErrors.ValidationErrorItem(
field + ' must be unique', 'unique violation', field, self.callee[field]));
field + ' must be unique', 'unique violation', field, self.callee && self.callee[field]));
});
Utils._.forOwn(this.callee.__options.uniqueKeys, function(constraint) {
if (Utils._.isEqual(constraint.fields, fields) && !!constraint.msg) {
message = constraint.msg;
return false;
}
});
if (this.callee) {
Utils._.forOwn(this.callee.__options.uniqueKeys, function(constraint) {
if (Utils._.isEqual(constraint.fields, fields) && !!constraint.msg) {
message = constraint.msg;
return false;
}
});
}
return new sequelizeErrors.UniqueConstraintError({
message: message,
......
......@@ -33,5 +33,17 @@ if (dialect === 'sqlite') {
});
});
});
describe('regression tests', function() {
it('do not crash while parsing unique constraint errors', function() {
var Payments = this.sequelize.define('payments', {});
return Payments.sync({force: true}).then(function () {
return (expect(Payments.bulkCreate([{id: 1}, {id: 1}], { ignoreDuplicates: false })).to.eventually.be.rejected);
});
});
});
});
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!