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

findOneAndUpdate when upsert: true crashes if query contains a null value #3135

Closed
odeke-em opened this issue Jul 3, 2015 · 3 comments
Closed
Milestone

Comments

@odeke-em
Copy link
Contributor

odeke-em commented Jul 3, 2015

targetModel.findOneAndUpdate({siteId: null}, {$set: {lastIndexingDate: Date.now()}, {upsert: true}, function(err, updatedItem) {
...
});

gives

/Users/emmanuelodeke/[redacted]/node_modules/newrelic/lib/transaction/tracer/index.js:168
      throw err
            ^
TypeError: Object.keys called on non-object
    at Function.keys (native)
    at module.exports (/Users/emmanuelodeke/[redacted]/node_modules/mongoose/lib/services/updateValidators.js:56:36)
    at Query._findAndModify (/Users/emmanuelodeke/[redacted]/node_modules/mongoose/lib/query.js:1651:18)
    at Query.findOneAndUpdate (/Users/emmanuelodeke/[redacted]/node_modules/mongoose/node_modules/mquery/lib/mquery.js:2118:15)
    at /Users/emmanuelodeke/[redacted]/node_modules/mongoose/node_modules/kareem/index.js:156:8
    at /Users/emmanuelodeke/[redacted]/node_modules/mongoose/node_modules/kareem/index.js:18:7
    at wrapped (/Users/emmanuelodeke/[redacted]/node_modules/newrelic/lib/transaction/tracer/index.js:157:28)
    at wrapped (/Users/emmanuelodeke/[redacted]/node_modules/newrelic/lib/transaction/tracer/index.js:157:28)
    at process._tickDomainCallback (node.js:486:13)
    at process.wrappedFunction (/Users/emmanuelodeke/[redacted]/node_modules/newrelic/lib/transaction/tracer/index.js:262:51)

I have been able to trace the cause of the crash and it is that Object.keys is being invoked on null because the previous check of typeof null === 'object' passes.
I'll be submitting a patch to fix it.

@vkarpov15
Copy link
Collaborator

Thanks for the detailed report, will fix.

@odeke-em
Copy link
Contributor Author

odeke-em commented Jul 9, 2015

Fixed by PR #3136. Did you want me to close this issue or would you prefer to close it yourself as part of your process?

@vkarpov15
Copy link
Collaborator

Closed it. Thanks for your help!

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

No branches or pull requests

2 participants