Removing item from a top-level Array, not a MongooseArray causes crash when saving #903

Closed
gubarez opened this Issue May 9, 2012 · 4 comments

Comments

Projects
None yet
2 participants

gubarez commented May 9, 2012

Again, I don't have a git client here... sorry :)

TypeError: Cannot read property '_path' of undefined
at /server/node_modules/mongoose/lib/document.js:881:25
at Array.forEach (native)
at model._dirty (/server/node_modules/mongoose/lib/document.js:872:7)
at model._delta (/server/node_modules/mongoose/lib/model.js:331:20)
at model.save (/server/node_modules/mongoose/lib/model.js:311:22)
at model. (/server/node_modules/mongoose/node_modules/hooks/hooks.js:59:24)
at /server/node_modules/mongoose/node_modules/hooks/hooks.js:52:28
at fnWrapper (/server/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)
at complete (/server/node_modules/mongoose/lib/document.js:761:5)
at /server/node_modules/mongoose/lib/document.js:777:20

I don't really know why this problem occurs...
location:
lib/document.js line 881:13

need to change from:

   if (!(item.value._path && item.value.doAtomics)) {

to:

   if (item.value && !(item.value._path && item.value.doAtomics)) {

The fix seems to work fine, but I didn't really check other behaviors.

Cheers!

Collaborator

aheckmann commented May 10, 2012

can you provide the code that causes this?

gubarez commented May 11, 2012

well... it would be difficult...
In general I do a several tasks, like - saving some fields of a Document instance and the problem occurs when removing...

However I didn't have the bug earlier... then the following change I have made:

From:

  1. Define Schema A
  2. Define Schema B, having an array of Schema A
  3. Define Schema C, having an array of Schema B

to

  1. Define Schema A
  2. Define Schema B1, having an array of Schema A
  3. Define Schema B2, having an array of IDs of Schema A (then I populate them...)
  4. Define Schema C, having an array of Schema B1

Note Schema B1 and B2 have exactly the same structure, except the difference of the definition of the instance of the array to Schema A.

Then
I define Schema A, Schema B2 and Schema C to have model instances.

Then I have a Schema B2 type fetched and populated Document to be pushed into the Schema B1 array of a Schema C Document. Finally I do certain manipulations, and remove the item from the array....

Its a bit complicated, I'll try to create a test case later.

Collaborator

aheckmann commented May 11, 2012

Thank you

On May 11, 2012, at 12:54 AM, gubarezreply@reply.github.com wrote:

well... it would be difficult...
In general I do a several tasks, like - saving some fields of a Document instance and the problem occurs when removing...

However I didn't have the bug earlier... then the following change I have made:

From:

  1. Define Schema A
  2. Define Schema B, having an array of Schema A
  3. Define Schema C, having an array of Schema B

to

  1. Define Schema A
    2.1. Define Schema B1, having an array of Schema A
    2.2. Define Schema B2, having an array of IDs of Schema A (then I populate them...)
  2. Define Schema C, having an array of Schema B1

Then
I define Schema A, Schema B2 and Schema C to have model instances.

Then I have a Schema B2 type fetched and populated Document to be pushed into the Schema B1 array of Schema C Document. Finally I do certain manipulations, and remove the item from the array....

Its a bit complicated, I'll try to create a test case later.


Reply to this email directly or view it on GitHub:
LearnBoost#903 (comment)

Collaborator

aheckmann commented Aug 2, 2012

closing, no response in over a month. please reopen if the problem still exists.

@aheckmann aheckmann closed this Aug 2, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment