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

Merged
merged 1 commit into from
Aug 4, 2024

Conversation

Sebmaster
Copy link
Contributor

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

Copy link
Member

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 merged commit b1b7265 into mongoosejs:master Aug 4, 2024
@Sebmaster Sebmaster deleted the fix/nulled-array branch August 4, 2024 21:04
@vkarpov15 vkarpov15 added this to the 2.1.1 milestone Aug 4, 2024
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
3 participants