Skip to content

Commit

Permalink
fix RangError: Maximum call stack exceeded error
Browse files Browse the repository at this point in the history
closes #714
relates to #688
  • Loading branch information
aheckmann committed Feb 3, 2012
1 parent 8653c73 commit 746afb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
7 changes: 5 additions & 2 deletions lib/model.js
Expand Up @@ -393,12 +393,15 @@ Model.prototype._delta = function _delta () {
} }
} }
} else { } else {
// normalize MongooseArray or MongooseNumber
if (type instanceof MongooseArray || if (type instanceof MongooseArray ||
type instanceof MongooseBuffer) { type instanceof MongooseBuffer) {
type = type.toObject({ depopulate: 1 }); type = type.toObject({ depopulate: 1 });
} else if (type._path) } else if (type._path) {
type = type.valueOf(); type = type.valueOf();
} else {
// nested object literal
type = utils.clone(type);
}


if (useSet) { if (useSet) {
if (!('$set' in delta)) if (!('$set' in delta))
Expand Down
48 changes: 17 additions & 31 deletions test/model.test.js
Expand Up @@ -800,43 +800,29 @@ module.exports = {
}); });
}, },


// gh-662 // gh-714
'test nested structure created by merging': function() { 'modified nested objects which contain MongoseNumbers should not cause a RangeError on save': function () {
var db = start(); var db =start()

var MergedSchema = new Schema({
a: {
foo: String
}
});


MergedSchema.add({ var schema = new Schema({
a: { nested: {
b: { num: Number
bar: String
} }
}
});

mongoose.model('Merged', MergedSchema);
var Merged = db.model('Merged', 'merged_' + Math.random());

var merged = new Merged({
a: {
foo: 'baz'
, b: {
bar: 'qux'
}
}
}); });


merged.save(function(err) { var M = db.model('NestedObjectWithMongooseNumber', schema);
var m = new M;
m.nested = null;
m.save(function (err) {
should.strictEqual(null, err); should.strictEqual(null, err);
Merged.findById(merged.id, function(err, found) {
db.close(); M.findById(m, function (err, m) {
should.strictEqual(null, err); should.strictEqual(null, err);
found.a.foo.should.eql('baz'); m.nested.num = 5;
found.a.b.bar.should.eql('qux'); m.save(function (err) {
db.close();
should.strictEqual(null, err);
});
}); });
}); });
}, },
Expand Down

0 comments on commit 746afb2

Please sign in to comment.