parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.88k stars 4.78k forks source link

customObjectId does not work with `beforeSave` triggers #6733

Open buitanloc opened 4 years ago

buitanloc commented 4 years ago

Issue Description

Steps to reproduce

Expected Results

Actual Outcome

Environment Setup

JeromeDeLeon commented 4 years ago

I think inside PServer, It uses JS-SDK and in it, it is not yet implemented. https://github.com/parse-community/Parse-SDK-JS/issues/1097

ArkeshGKalathiya commented 4 years ago

Any update on this? I am having same issue. I was saving custom object ids from express app, and it was working fine. And as soon as I add beforeSave trigger, it started discarding the provided custom ids, and stored objects with newly generated ids by parse.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

felix-ht commented 3 years ago

I can confirm - we have the same issue

bdevore17 commented 3 years ago

Same!

felix-ht commented 3 years ago

@JeromeDeLeon

So i found the reason and a solution. getResponseObject calls _getSaveJSON this in turn removes the objectId.

A simple solution would be to add this to the resolver of getResponseObject. This fixes the issue - as it adds the id back if it is missing from modified object!

if (triggerType === Types.beforeSave && config.allowCustomObjectId && parseObjectJson.objectId) {
        object.object.objectId = parseObjectJson.objectId
}

another option would the to just remove _getSaveJSON if allowCustomObjectId is set. This should be fine as this is not called if a before save trigger ist not set, so removing it will probably not have any side effects. Checking ensures that it would change stuff in cases where the current codebase is already broken.

 if (request.triggerName === Types.beforeSave && !config.allowCustomObjectId) {
    response['object'] = request.object._getSaveJSON();
  }
JeromeDeLeon commented 3 years ago

It would be better if you could create a PR for this to further discuss this. @felix-ht

dplewis commented 3 years ago

allowCustomObjectId has been added to the JS SDK and merged with the server.

https://github.com/parse-community/parse-server/pull/7222

I'll try to do a PR to fix this issue.

canyousayyes commented 3 years ago

We countered the same issue and glad to know the bug fix has been merged. Any plans to release this fix in the soon future?

lsmilek1 commented 3 years ago

+1 - Any plans to release this fix in the soon future?

gtzinos commented 2 years ago

any update on this?

mtrezza commented 2 years ago

The first step would be to open a PR and demonstrate the issue with a failing test. From there, we can look for a fix.