Cloud Code object.save () results in an "object not found" with a very strange PUT command

Description of the problem

I have a simple Cloud Code command to create or update an object. If NO objectId fails, the procedure creates a new object and returns objectId. If objectId exists in the parameter list, it retrieves the object and updates the parameters accordingly.

The subroutine works great for new objects.

The object.save() error object.save() while trying to update the object, despite the operation of the object.fetch() routine.

error: code = 101, message = Object not found.

Vertex server logs indicate a very strange PUT command ...

PUT / parse / classes / Receipt / [object% 20Object]

what i expect to see

PUT / parse / classes / Receipt / GJaXcf7fLD

ACL object is public r + w

Why object.save() not work with a valid object?

_

Cloud code

 Parse.Cloud.define("uploadReceipt", function(request,response) { var Receipt = Parse.Object.extend("Receipt"); var receipt = new Receipt(); // passed in parameters are ['property' : ['type' : t, 'value' : v]] var dict = request.params; var objectIdDict = dict["objectId"]; console.log("Object Dict: " + objectIdDict); Parse.Promise.as().then(function() { // if we already have an objectId we are UPDATING // Need to FETCH first if (objectIdDict != undefined) { console.log("Searching for ID: " + objectIdDict["value"]); receipt.set("objectId",objectIdDict["value"]); return receipt.fetch(); } else { console.log("NEW RECEIPT"); return Parse.Promise.as(receipt); } }).then(function(receipt) { console.log("Receipt: " + receipt.id); // copy over the keys from our passed in parameters to the object for (var key in dict) { //console.log("Key: " + key + " Value: " + dict[key]["value"]); if (dict[key]["type"] == "Raw") { console.log("Key: " + key + " Value: " + dict[key]["value"]); receipt.set(key,dict[key]["value"]); } else if (dict[key]["type"] == "Date" && key != "updatedAt") { console.log("Key: " + key + " Value: " + dict[key]["value"]); var time = dict[key]["value"] * 1000; // milliseconds receipt.set(key,new Date(time)); } else { // object type var Obj = Parse.Object.extend(dict[key]["type"]); var newObj = new Obj(); newObj.id = dict[key]["value"]; receipt.set(key,newObj); } } // make sure our user is set receipt.set("user",request.user); // adjust the status because it has now been uploaded receipt.set("status",RECEIPT_SUBMITTED); console.log("Prior to save"); return receipt.save(); }).then(function(receipt) { console.log("Finished"); response.success({"status":receipt.get("status"),"objectId":receipt.id}); },function (error) { console.log(error); response.error(error); }); }); 

Steps to play

  • Call a cloud code from the iOS SDK with data for a new object
  • Note that the command works and a new object is added to the database
  • Call the team with updated information
  • Please note that the command does not work with not found

Expected results

Object must be updated accordingly.

Actual result

error: code = 101, message = Object not found.

Environment setup

  • Server

    • parse-server version: 2.2.12
    • Operating System: Mac OS X 10.11.5
    • Hardware: MacBook Pro 2010
    • Local or remote server? Localhost
    • Javascript: Parse / js1.8.5
    • NodeJS 5.10.1
  • Database

    • MongoDB Version: 3.2.4
    • Hardware: MacBook Pro 2010
    • Local or remote server? Localhost

Logs / Tracing

Saving new objects

 verbose: POST /parse/classes/Receipt { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.5 (NodeJS 5.10.1)', accept: '*/*', 'content-type': 'text/plain', host: 'localhost:1337', 'content-length': '471', connection: 'close' } { "date": { "__type": "Date", "iso": "2016-06-19T00:30:37.492Z" }, "category": { "__type": "Pointer", "className": "Category", "objectId": "XZ1bSHtZBY" }, "status": 0, "amount": 61.45, "notes": "Hopefully this works well", "gui_status": -1, "currency": "USD", "user": { "__type": "Pointer", "className": "_User", "objectId": "vL4ih9BAX8" } } verbose: { "status": 201, "response": { "objectId": "GJaXcf7fLD", "createdAt": "2016-06-19T00:30:57.092Z" }, "location": "http://localhost:1337/parse/classes/Receipt/GJaXcf7fLD" } Finished verbose: { "response": { "result": { "status": 0, "objectId": "GJaXcf7fLD" } } } 

An attempt to update objects returns

 verbose: PUT /parse/classes/Receipt/[object%20Object] { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.5 (NodeJS 5.10.1)', accept: '*/*', 'content-type': 'text/plain', host: 'localhost:1337', 'content-length': '473', connection: 'close' } { "category": { "__type": "Pointer", "className": "Category", "objectId": "XZ1bSHtZBY" }, "status": 0, "amount": 5.47, "notes": "How about now", "gui_status": 0, "date": { "__type": "Date", "iso": "2016-06-19T00:12:25.788Z" }, "currency": "USD", "user": { "__type": "Pointer", "className": "_User", "objectId": "vL4ih9BAX8" } } verbose: error: code=101, message=Object not found. ParseError { code: 101, message: 'Object not found.' } verbose: error: code=141, code=101, message=Object not found. 
+8
javascript parse-server
source share
1 answer

Found this out with some help from the parsing community and GitHub user flovilmart

In case of "updating" the object, I turned on the dictionary entry for the receipt. This managed to get the receipt I wanted to update.

However, the problem was that as soon as I pulled the object into the receipt and repeated it in my properties dictionary for updating ... I again ran into information about the receiving object. Thus, I tried to add the Receipt receipt property to my receipt with the pointer itself! Ugh.

The most recent else clause required him to NOT include a receipt pointer (itself)

  for (var key in dict) { if .... else if (dict[key]["type"] != "Receipt"){ // object type, but don't include ourself! (the Receipt) var Obj = Parse.Object.extend(dict[key]["type"]); var newObj = new Obj(); newObj.set("objectId",dict[key]["value"]); receipt.set(key,newObj); } } 
+4
source share

All Articles