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 non-object attributes being passed to model.parse() #2056

merged 4 commits into from Mar 22, 2020


Copy link


When is executed with method: 'update', the resp argument is first the number of rows that were updated. This causes undefined to be passed into this.parse on line 1183 in Any custom model.parse functions on a model are expecting an object of attributes to be passed.

Also, this branch can be reached if the save method is 'insert' and is not null, which we have found to occur when query.options.returning was set to 'id' instead of the default '*' which bookshelf expects.


Any custom model.parse functions are not expecting to be receiving any argument other than an object, potentially causing unexpected errors.

Proposed solution

Check that the response is an object before passing it to model.parse and merging with this.attributes.

Copy link

Won't this fix mean that we will still be left without the updated attributes?

Copy link
Contributor Author

@ricardograca When the query returns the updated attributes in an object, yes it will add the updated attributes. Added a unit test for that behavior.

Perhaps you know more about why this is, but I found that this code gets called twice on a - the first time resp is number of rows updated, the second time it receives an array containing the object with all model attributes.

Thank you for the review!

@ricardograca ricardograca merged commit 45c23b4 into bookshelf:master Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

.save({method: 'insert') is attempting to parse() undefined objects
2 participants