-
-
Notifications
You must be signed in to change notification settings - Fork 595
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
feat: Allow saving with custom objectId #1309
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1309 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 60 60
Lines 5836 5851 +15
Branches 1310 1314 +4
=========================================
+ Hits 5836 5851 +15
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just a question, if we were to merge this and update the Parse-Server, would it be allowed to use with save trigger?
@JeromeDeLeon The purpose of this PR is to allow the customId to get sent to the server. I wrote a quick test and the beforeSave trigger gets called but the behavior looks wrong. Might need a server update. |
@@ -2375,6 +2384,12 @@ const DefaultController = { | |||
if (el instanceof ParseFile) { | |||
filesSaved.push(el.save(options)); | |||
} else if (el instanceof ParseObject) { | |||
if (allowCustomObjectId && !el.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forces all objects to have custom ids, if custom ids are allowed.
Is this intentional? This is not how the server treats allowCustomObjectId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second this. Just turned this on, and this does not work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend looking at #1309 (comment)
Hi, I am trying to set my own Id with this new feature. In my parse options for parse-server, I added the allowCustomObjectId to be true. Is there another thing i need to do with Parse JS SDK? |
Currently, one also needs to set allowCustomObjectId on the client side, which I find to be weird. It is used to decide between doing a POST and a PUT, in conjunction with updatedAt, which I find to be even weirder. Perhaps a later PR can modify the js sdk to have a create()/update() seperation instead, like the Dart sdk? |
That indeed needs a closer look. Can you give more details / examples for what you described? The difference between POST and PUT should whether the object already exists or is newly created, not how the object ID is set. |
So what is the notation to allow for custom IDs on the client side? Parse-server automatically creates the js sdk so i am confused as where i declare it on client side |
I am not sure what you mean by the server automatically creating the sdk. |
That isn't working. I added that line to the top of my cloud function, and i am still getting an object not found error, due to the custom id.... |
Weird. Unless you are using an outdated version of the server, you might want to open an issue. |
Are you intending to switch between custom and non-custom IDs during runtime? I'm not sure such a fundamental change should be possible during run-time, or even at all for a deployment. |
Please see the code. Because the server doesn't support upsert (see parse-community/parse-server#7139), the SDK ends up having to guess whether to use POST (which fails if the object already exists) or PUT (which fails if the object does not already exist). The way it does that is by checking if To see the way the Flutter SDK does it, see its source. It has a |
We want to allow custom ids, but the changes in this PR forces us to either always use custom object ids, or to disallow them altogether. The way we currently work around this is by toggling the sdk's flag. The server is set to allow custom object ids all the time. |
In my application I found also a use case for the mixed environment of server generated and custom objectId (ParseSwift SDK, forum) and would like to implement allow instead of force. From what I tested with forked ParseSwift SDK where I removed the guards that are checking that
So from this point of view there is no urgent need for separate |
Though what @mstniy stated above is true, particularly "forces all objects to have custom ids..." . I don't think removing the checks that @dplewis added should be done as they make sure the proper items are needed when using a custom objectId. Instead, I recommend using an approach similar to the Swift SDK parse-community/Parse-Swift#222 (comment) in which a flag,
Basically, if the developer "really" wants a mixed environment, they should do so at their own risk. I can easily see devs raising issues on the server and SDK repos for handling the above warning incorrectly. |
I see, that could be also a way to go. I am just still missing what is being protected exactly or at least it feels redundant, because from what I tested in ParseSwift SDK, it behaves correctly (assuming the
At least with ParseSwift SDK it work that way when I turned of the guards in forked SDK. Edit: in your comit I can see the concern and finally understood it! |
Closes: #1097
Ref: parse-community/parse-server#6177
@JeromeDeLeon