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

beforeSave() hook causes "Object Not Found" error #6195

Closed
drhuanliu opened this issue Nov 7, 2019 · 7 comments
Closed

beforeSave() hook causes "Object Not Found" error #6195

drhuanliu opened this issue Nov 7, 2019 · 7 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@drhuanliu
Copy link

Issue Description

I just upgrade from Parse Server 2.7 to 3.9, and this new issue starts to happen:

  • We save a bunch of PFObjects from iOS in bulk with PFObject.saveAll(inBackground: array.....
  • In ParseServer, we have a beforeSave, and afterSave hook to do extra steps
  • When saving more than one object, the server would return "Object Not Found" error

I trace the error to line 209 of RestWrite.js. Apparently, this call

databasePromise = this.config.database.create(this.className, this.data, this.runOptions, true);

does not return back an object, resulting in throwing an exception.

Here is what I know:

  • Problem does not happen in 2.7
  • Problem does not happen if just save one object
  • Problem does not happen if I do not declare the beforeSave function
  • Problem does happen if I declare the beforeSave function, even if the function is empty (doing nothing)

Could you please take a look at that section of the RestWrite.js code, and see what could potentially be causing it to raise an exception?

Steps to reproduce

  • Write a cloud code function with beforeSave for a class X
  • Save an array of class X objects from iOS clients

Expected Results

  • I expect all saves to be successful

Actual Outcome

  • Get "object not found" exception

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 3.9
    • Operating System: Windows
    • Hardware: Azure cloud
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Azure
  • Database

    • MongoDB version: 3.2.1 Community
    • Storage engine: not sure
    • Hardware: Azure
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Azure

Logs/Trace

Include all relevant logs. You can turn on additional logging by configuring VERBOSE=1 in your environment.

@dplewis
Copy link
Member

dplewis commented Nov 7, 2019

If you remove the beforeSave hook do the objects save?
Does your objects exist in the DB?

@drhuanliu
Copy link
Author

Yes, if I remove beforeSave hook, object saves and exists in DB.

I may have isolated the issue already. I added some logs, it seems that if one of the Number object field is 0, the this.config.database.create call will fail to return an object. I will upload some logs later tonight.

@dplewis
Copy link
Member

dplewis commented Nov 16, 2019

@drhuanliu any updates?

@wqzyow
Copy link

wqzyow commented Jan 5, 2020

Same issue here. beforeSave() was not triggered for only one parse subclass. After investigation/debugging, turned out I was using a field/column named "length" on that parse subclass. Renaming that column fixed the issue.

Believe the error is being thrown because of one line in RestWrite.js:

      if (!result || result.length <= 0) {
        throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
      }

result.length returns 0 when the 'length' column value is 0.

@dplewis
Copy link
Member

dplewis commented Jan 6, 2020

@wqzyow That is interesting. We can do a PR for that. @drhuanliu Are you experiencing anything similar?

@mtrezza mtrezza added needs more info type:bug Impaired feature or lacking behavior that is likely assumed and removed needs investigation labels Nov 1, 2020
@sunshineo
Copy link
Contributor

This can be reproduced without involving beforeSave
Just create a class with column length with type Number and try post to it
This works {"length":1}
This does not {"length":0} and returns that error

@mtrezza
Copy link
Member

mtrezza commented Nov 11, 2020

Thanks for confirming. Would you be willing to open a PR for this and start by adding a failing test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

5 participants