-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
beforeSave request object changes ignored #5227
Comments
Would you be able to write a failing test? |
Hey @flovilmart, @dplewis instructed me to copy/paste this test and add a return to the hook: https://github.com/parse-community/parse-server/blob/master/spec/CloudCode.spec.js#L165 I did that and ran the tests and the test failed. I don't know where to take it from there though, since I've never submitted a failing test. Do I branch and do a pull request? |
NICE!! Yes, fork parse-server, create a branch, add your test, push to your fork and make a pull request. here's step by step directions: https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project WELCOME! |
I just submitted the pull request. I wasn't too sure on the branch name (idk if there's conventions) but hopefully everything is in order. @acinader thanks for your help! |
Just want a moment to recognize @blastoy's example of a good issue description 👍 |
The label |
Issue Description
When defining a beforeSave hook, any changes done to the request object will not apply if the hook function returns true. For example:
If the return is omitted, then the beforeSave hook works just fine.
If returning a Promise that returns true, the beforeSave does not apply any changes either. For example:
I haven't tried with returning other things like strings, but I'm assuming it would also cause the same issue.
An argument could be made that beforeSaves should not return any values anyway and that this kind of bug is a developer error. However, some of the code samples on the migration guide to parse-server 3.0 have beforeSave examples were returns are used. This may lead developers to think returning in beforeSave hooks is safe.
Personally I believe this bug should be fixed so that the beforeSaves returning do not affect the ability to make changes to the request object. If that is deemed to be unnecessary, then a proper warning / changes to the migration guide could be helpful. This kind of bug is pretty difficult to find if your beforeSaves have considerable amounts of logic in them (such as data validation and formatting), and I find it strange that cloud jobs / functions can return just fine while hooks cannot.
Steps to reproduce
Foo
.request.object.set('name', 'bar');
.return true
.replace_me
.Expected Results
Modifications should go through and the Parse object. The object's name field should be
bar
if following the example above.Actual Outcome
Modifications do not go through. The object's name stays as 'replace_me' if following the example above.
Environment Setup
Server
3.1.2
Windows 10 Education
i5-7500 3.40 GHz, 64 bit, 16 GB RAM
Localhost server
Database
v3.6.5
GridFSBucketAdapter
i5-7500 3.40 GHz, 64 bit, 16 GB RAM
Localhost server
Logs/Trace
The text was updated successfully, but these errors were encountered: