-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property 'length' of undefined #5896
Comments
This change introduced the crashing code: |
Do you have a code sample that reproduces this? Shouldn't be any way for a schema to not have a |
Also, no intentional breaking changes between those versions. |
Here are some code snippets of the used schemes:
The clone module is being used and createProjectDataSchema() is:
I am using a template schema and customized sub-schemas where the data field contains typed fields. But I guess the [ GlobalScene ] causes the issue. |
I narrowed this down to a subtle bug in clone: pvorb/clone#88 . Wish there was something I could do to make this work with mongoose, but until that PR is merged every JS class that declares properties on the prototype does not work with clone, including all of mongoose. As a workaround, I'd recommend you use lodash.clonedeep, it should be a drop-in replacement for clone and doesn't suffer from this issue. Although in this case I don't think you even need deep cloning, so you might just try doing |
Thanks a lot for the analysis. Object.assign() is enough in my cases. Happy holidays and keep up the great work! |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Mongoose 4.13.6 crashes where 4.11.13 was working fine.
If the current behavior is a bug, please provide the steps to reproduce.
Our schemas are use child schemas. Mongoose accesses a length property which does not exist.
This is the stack trace:
TypeError: Cannot read property 'length' of undefined
at Mongoose._applyPlugins (Z:\git\pharos-node-server\node_modules\mongoose\lib\index.js:486:40)
at Mongoose._applyPlugins (Z:\git\pharos-node-server\node_modules\mongoose\lib\index.js:487:10)
at Mongoose._applyPlugins (Z:\git\pharos-node-server\node_modules\mongoose\lib\index.js:487:10)
at Mongoose.model (Z:\git\pharos-node-server\node_modules\mongoose\lib\index.js:396:10)
Are there breaking changes between those versions concerning child schemas?
What is the expected behavior?
Should not crash.
Please mention your node.js, mongoose and MongoDB version.
Node v8.4.0 and MongoDB 3.8.
The text was updated successfully, but these errors were encountered: