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

set('key', undefined) in Cloud Code does not result in key being undefined in beforeSave #1942

Closed
airdrummingfool opened this issue May 29, 2016 · 7 comments

Comments

@airdrummingfool
Copy link
Contributor

airdrummingfool commented May 29, 2016

Saving an object after calling set('key', undefined) does not result in key being undefined in beforeSave. Once beforeSave has completed and the save call returns, key is undefined as expected.

This might be related to #1840. Test incoming.

@flovilmart
Copy link
Contributor

When not providing any value, the JS-SDK will interpolate it as a no-op as this is equivalent as calling set('key'). A missing argument will be set to undefined.

@airdrummingfool
Copy link
Contributor Author

airdrummingfool commented May 30, 2016

@flovilmart I'm not sure I understand. As the test in my PR shows, calling object.set('key', undefined) does eventually set key to undefined, it just doesn't take affect until after beforeSave is executed, which is inconsistent with seting keys to other (non-undefined) values. This assumes key was previously not undefined, otherwise yes, seting an undefined value to undefined would be a no-op (I should have made that clear in the issue description, sorry).

e.g.:

  1. Create TestObject, set 'key' to 'hello' using set('key', 'hello');
  2. Save TestObject. In beforeSave, log value of key (output is "hello", as expected).
  3. Set 'key' to undefined, using set('key', undefined);
  4. Save TestObject again. In beforeSave, log value of key. Expected output is undefined, but actual output is "hello".
  5. Once save is complete, log value of key again. Value is now undefined as expected.

@flovilmart
Copy link
Contributor

The main issue is that undefined is not serializable, so anything that gets set to undefined server side can't be forwarded to the client, unless a fetch is done.

@airdrummingfool
Copy link
Contributor Author

It still affects Cloud Code functions that modify and then return an object (i.e. most things not the result of a client-side save() call), right? Or is seting a key to undefined not supported, and instead we should use unset()?

@flovilmart
Copy link
Contributor

You should use unset, and unset itself is broken, as you noticed. I've opened PR on the iOS and JS SDK's to improve that.

@airdrummingfool
Copy link
Contributor Author

Great, thanks for the clarifications.

@drbarto
Copy link

drbarto commented Mar 29, 2017

@flovilmart I maybe have a problem that is related to the mentioned brokenness of unset. What's the status of your PR, can you please post a link?

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

No branches or pull requests

3 participants