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

Change to Object.prototype.hasOwnProperty.call due to changes in node.js. Also check for null. #1

Merged
merged 2 commits into from
Aug 8, 2017

Conversation

mika-s
Copy link
Contributor

@mika-s mika-s commented Aug 2, 2017

I was getting this error message when using mongoose-patch-update with node.js v7.10:

TypeError: updateData.hasOwnProperty is not a function
at findOne.select.exec.then (C:\x\node_modules\mongoose-patch-update\index.js:34:43)
at newTickHandler (C:\x\node_modules\mpromise\lib\promise.js:234:18)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)

There have been some changes in node.js v.6.x that is the cause of this error. It's discussed here.

Another problem I had was when trying to update a field in the model that was null before. It gave the following error:

TypeError: Cannot convert undefined or null to object
at Function.keys ()
at findOne.select.exec.then (C:\x\node_modules\mongoose-patch-update\index.js:32:103)
at newTickHandler (C:\x\node_modules\mpromise\lib\promise.js:234:18)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9),
status: 400 }

typeof modelInstance[attribute] == 'object' will return true when the type is null, so I added an extra check for null.

Due to changes in nodejs v6.x. See nodejs/node#6289.
The function would throw "TypeError: Cannot convert undefined or null to object" if the field to update was null previously.
@jbutko jbutko merged commit a797fb9 into jbutko:master Aug 8, 2017
@jbutko
Copy link
Owner

jbutko commented Aug 8, 2017

Great thanks for the fix.

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.

2 participants