[CloudCode] Unsetting a ParseFile in beforeSave does not work as expected
Issue Description
On hosted Parse we had a construct in our CloudCode where we unset a ParseFile (User.thumbnail) in the beforeSave of a user object if another field in the object (User.image) was dirty. In the afterSave we then checked if the object does not have a value for the field (!User.has("thumbnail")) and then filled it with a new value. With the new setup this doesn't work anymore because !User.has("thumbnail") is never true nor is User.get("thumbnail") == null in the afterSave and therefore the thumbnail will never be set to its new value.
Today I rearranged the code so that the thumbnail generation takes place in the beforeSave but maybe there are other people struggling with this exact problem.
Steps to reproduce
- Use the
beforeSaveof the class User tounsetaParseFile-field - Check if the field is empty in the
afterSavewith!request.object.has("fieldName") - The field is neither
nullnor is!request.object.has("fieldName")
Expected Results
!request.object.has("fieldName") should be true in the afterSave
Actual Outcome
!request.object.has("fieldName") is false
Environment Setup
- Server
- parse-server version: 2.2.10
- Operating System: OSX 10.11.5 / Amazon Linux
- Localhost / AWS Elastic Beanstalk
- Database
- MongoDB version: 3.2
- Storage engine: default
- Localhost / AWS EC2
Hey @j-koenig thanks for reporting this. How is the beforeSave hook defined? Is it via cloudCode or via web hook? Is it just the field with the Parse.File or does unsetting any other field also not work?
Hey @TylerBrock, the beforeSave is defined in the CloudCode and I experienced the problem only with ParseFile fields. Unsetting other fields works as expected.
I can confirm the same issue with unset at afterSave with a field of type Date.
Please update to latest parse-server, as I can't reproduce (see the open PR). Closing for now, please reopen if the reproduction is not accurate with what you're expecting.