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

Explicitly setting a property of a record to "undefined" and saving it to the database stores null instead of undefined #9139

Open
anders-topp opened this issue May 29, 2024 · 5 comments
Labels
type:question Support or code-level question

Comments

@anders-topp
Copy link

anders-topp commented May 29, 2024

New Issue Checklist

Issue Description

Recently upgraded from Parse 4.10 to Parse 6.5 and noticed the following change in behavior which i assume is a bug.

When storing a record in the database that has a property explicitly set to "undefined", a null value is stored.
I.e. the behavior is different than if you do not set a property on the object as save it.
Again, in Parse 4.10, storing a property explicitly set to undefined, did not touch the property (i.e. left it to whatever it was before, for example undefined).

Steps to reproduce

Use the JS SDK.
Create an empty record in the parse dashboard.
explicitly set a property to "undefined" of a record using the JS sdk.
store the record.
look at the database in the dashboard and see that the value is Null instead of undefined

Actual Outcome

Null stored in the property of the db

Expected Outcome

The property not to be updated

Environment

Server

  • Parse Server version: 6.5
  • Operating system: Mac OSX Sonoma 14.4/Node
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 6.0.15
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Atlas

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScript
  • SDK version: 4.1

Logs

Copy link

parse-github-assistant bot commented May 29, 2024

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza
Copy link
Member

mtrezza commented May 29, 2024

Why would you set a property to undefined - or anything for that matter - if you don't want it to change?

@mtrezza mtrezza added the type:question Support or code-level question label May 29, 2024
@anders-topp
Copy link
Author

You might have code like this
const obj = {
prop1:1,
optionalProp2:2,
// optionalProp3:3 in this case this property is not set
}

myRecord.a = obj.prop1;
myRecord.b = obj.optionalProp2;
myRecord.c = obj.optionalProp3; // this will explicity set c to "undefined" if this property was not set 'obj'

Of course it's easy to avoid this by checking for undefined before assigning, but that assumes you understand the difference between an unassigned property and a property set to "undefined" and know that Parse treats these cases differently.

@anders-topp
Copy link
Author

... sorry, part of my last response was lost.

But doing Object.keys (myRecord) and then set all these values using the JS SDK would cause a record.Set ("optionalProp3", undefined);.

Anyway, the behaviour is different than older Parse versions so it should at least be captured in release notes / migration notes.

@mtrezza
Copy link
Member

mtrezza commented May 29, 2024

Did you check the changelog entries of the releases? This change may be a deliberate result of a previous discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

2 participants