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

Commit 83558e4d by Ruben Bridgewater

Try to fix sqlite crash while parsing unique constraint errors. Fixes #3546

1 parent 642fbbd2
# Next # Next
- [BUG] fix showIndexQuery so appropriate indexes are returned when a schema is used - [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 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 # 2.1.3
- [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667) - [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() { ...@@ -215,15 +215,17 @@ module.exports = (function() {
fields.forEach(function(field) { fields.forEach(function(field) {
errors.push(new sequelizeErrors.ValidationErrorItem( 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 (this.callee) {
if (Utils._.isEqual(constraint.fields, fields) && !!constraint.msg) { Utils._.forOwn(this.callee.__options.uniqueKeys, function(constraint) {
message = constraint.msg; if (Utils._.isEqual(constraint.fields, fields) && !!constraint.msg) {
return false; message = constraint.msg;
} return false;
}); }
});
}
return new sequelizeErrors.UniqueConstraintError({ return new sequelizeErrors.UniqueConstraintError({
message: message, message: message,
......
...@@ -33,5 +33,17 @@ if (dialect === 'sqlite') { ...@@ -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!