You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like the fix for issue #5405 breaks error handling middleware on save.
With Mongoose 4.11.2 the 2nd argument of the error handling middleware is indeed null, while it is the document - as expected - with earlier Mongoose versions.
Here's a repro:
constassert=require('assert');constmongoose=require('mongoose');constGITHUB_ISSUE=`gh-5466`;mongoose.connect(`mongodb://localhost:27017/${GITHUB_ISSUE}`);varSchema=mongoose.Schema;describe('Error Handling Middleware',function(){before(asyncfunction(){awaitmongoose.connection.dropDatabase();});it('On save res should not be null',function(done){varschema=newSchema({name: {type: String,unique: true}});varhandleE11000=function(error,res,next){assert.equal(error.name,'MongoError');assert.equal(error.code,11000);assert.equal(typeofnext,'function');assert.notStrictEqual(null,res);// with mongoose 4.11.1 and below res is the document; with 4.11.2+ is nullnext();};schema.post('save',handleE11000);varPerson=mongoose.model('Person',schema);varperson1={name: 'David'};varperson2={name: 'David'};Person.on('index',function(error){assert.ifError(error);Person.create([person1,person2],function(error){done();});});});});
Software version:
Node 6.10.2
Mongodb 3.4.1
Mongoose 4.11.2 and above are affected; versions 4.11.1 and below work correctly
The text was updated successfully, but these errors were encountered:
Looks like the fix for issue #5405 breaks error handling middleware on
save
.With Mongoose 4.11.2 the 2nd argument of the error handling middleware is indeed
null
, while it is the document - as expected - with earlier Mongoose versions.Here's a repro:
Software version:
Node 6.10.2
Mongodb 3.4.1
Mongoose 4.11.2 and above are affected; versions 4.11.1 and below work correctly
The text was updated successfully, but these errors were encountered: