Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix RangError: Maximum call stack exceeded error

closes #714
relates to #688
  • Loading branch information...
commit 746afb27d2121e820ba4a0327930c8f18e14d6b1 1 parent 8653c73
@aheckmann aheckmann authored
Showing with 22 additions and 33 deletions.
  1. +5 −2 lib/model.js
  2. +17 −31 test/model.test.js
View
7 lib/model.js
@@ -393,12 +393,15 @@ Model.prototype._delta = function _delta () {
}
}
} else {
- // normalize MongooseArray or MongooseNumber
if (type instanceof MongooseArray ||
type instanceof MongooseBuffer) {
type = type.toObject({ depopulate: 1 });
- } else if (type._path)
+ } else if (type._path) {
type = type.valueOf();
+ } else {
+ // nested object literal
+ type = utils.clone(type);
+ }
if (useSet) {
if (!('$set' in delta))
View
48 test/model.test.js
@@ -800,43 +800,29 @@ module.exports = {
});
},
- // gh-662
- 'test nested structure created by merging': function() {
- var db = start();
-
- var MergedSchema = new Schema({
- a: {
- foo: String
- }
- });
+ // gh-714
+ 'modified nested objects which contain MongoseNumbers should not cause a RangeError on save': function () {
+ var db =start()
- MergedSchema.add({
- a: {
- b: {
- bar: String
+ var schema = new Schema({
+ nested: {
+ num: Number
}
- }
- });
-
- 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);
- Merged.findById(merged.id, function(err, found) {
- db.close();
+
+ M.findById(m, function (err, m) {
should.strictEqual(null, err);
- found.a.foo.should.eql('baz');
- found.a.b.bar.should.eql('qux');
+ m.nested.num = 5;
+ m.save(function (err) {
+ db.close();
+ should.strictEqual(null, err);
+ });
});
});
},
Please sign in to comment.
Something went wrong with that request. Please try again.