parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

[CloudCode] Unsetting a ParseFile in beforeSave does not work as expected

Open j-koenig opened this issue 10 years ago • 4 comments

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

  1. Use the beforeSave of the class User to unset a ParseFile-field
  2. Check if the field is empty in the afterSave with !request.object.has("fieldName")
  3. The field is neither null nor 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

j-koenig avatar May 27 '16 12:05 j-koenig

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?

TylerBrock avatar May 28 '16 09:05 TylerBrock

Hey @TylerBrock, the beforeSave is defined in the CloudCode and I experienced the problem only with ParseFile fields. Unsetting other fields works as expected.

j-koenig avatar May 30 '16 08:05 j-koenig

I can confirm the same issue with unset at afterSave with a field of type Date.

mtrezza avatar Jun 21 '16 01:06 mtrezza

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.

flovilmart avatar Sep 18 '16 23:09 flovilmart