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

Commit 77506b42 by Sushant Committed by GitHub

fix(mssql): no unique constraint error thrown for PRIMARY case (#9415)

1 parent 6590873f
...@@ -259,7 +259,7 @@ class Query extends AbstractQuery { ...@@ -259,7 +259,7 @@ class Query extends AbstractQuery {
formatError(err) { formatError(err) {
let match; let match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/); match = err.message.match(/Violation of (?:UNIQUE|PRIMARY) KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/);
match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/); match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/);
if (match && match.length > 1) { if (match && match.length > 1) {
let fields = {}; let fields = {};
......
...@@ -9,7 +9,6 @@ const chai = require('chai'), ...@@ -9,7 +9,6 @@ const chai = require('chai'),
describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
describe('API Surface', () => { describe('API Surface', () => {
it('Should have the Error constructors exposed', () => { it('Should have the Error constructors exposed', () => {
expect(Sequelize).to.have.property('Error'); expect(Sequelize).to.have.property('Error');
expect(Sequelize).to.have.property('ValidationError'); expect(Sequelize).to.have.property('ValidationError');
...@@ -348,11 +347,23 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { ...@@ -348,11 +347,23 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
} }
}, { timestamps: false }); }, { timestamps: false });
return this.sequelize.sync({ force: true }).bind(this).then(() => { return this.sequelize.sync({ force: true })
.then(() => {
return User.create({ name: 'jan' }); return User.create({ name: 'jan' });
}).then(() => { }).then(() => {
// Unique key
return expect(User.create({ name: 'jan' })).to.be.rejected; return expect(User.create({ name: 'jan' })).to.be.rejected;
}).then(function(error) { }).then(error => {
expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError);
expect(error).to.have.property('parent');
expect(error).to.have.property('original');
expect(error).to.have.property('sql');
return User.create({ id: 2, name: 'jon' });
}).then(() => {
// Primary key
return expect(User.create({ id: 2, name: 'jon' })).to.be.rejected;
}).then(error => {
expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError); expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError);
expect(error).to.have.property('parent'); expect(error).to.have.property('parent');
expect(error).to.have.property('original'); expect(error).to.have.property('original');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!