Skip to content
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

Fix errors on null value array types #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sebmaster
Copy link

Summary

mongoose queries error when processing a record which contains null as a value of an Array schema type.

TypeError: Cannot read properties of null (reading 'map')
    at /mongoose-test/node_modules/mongoose-lean-getters/index.js:130:67
    at Schema.eachPath (/mongoose-test/node_modules/mongoose/lib/schema.js:1569:5)
    at model.Query.applyGettersToDoc (/mongoose-test/node_modules/mongoose-lean-getters/index.js:110:16)
    at model.Query.applyGetters (/mongoose-test/node_modules/mongoose-lean-getters/index.js:51:25)
    at model.Query.<anonymous> (/mongoose-test/node_modules/mongoose-lean-getters/index.js:36:18)
    at next (/mongoose-test/node_modules/kareem/index.js:268:35)
    at Kareem.execPost (/mongoose-test/node_modules/kareem/index.js:296:3)
    at /mongoose-test/node_modules/mongoose/lib/query.js:4380:28
    at new Promise (<anonymous>)
    at _executePostHooks (/mongoose-test/node_modules/mongoose/lib/query.js:4377:10)

With this change we check for non-null after running possible array getters, but before running the for-each-element .map(). If the value is indeed null, we'll bail out of processing array elements, instead just continuing with the non-array codepath.

Fixes #35.

@nadavhalfon
Copy link

I think it caused because this fix:
#32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error is thrown on Array schema types with null value
2 participants