parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Masterkey appears not to be working for functions triggered via Jobs

Open Roost opened this issue 9 years ago • 8 comments

Parse-Server 2.6.2

We are slow to migrate away from Parse.Cloud.useMasterKey() useage, but an issue we are seeing while doing this relates to various Jobs running without the need for a logged in user. These Job functions use the {useMasterkey: true} option where applicable. The objects that they interact with have the ACL's as public read only, and any call to object.save(null, {useMasterKey: true}) fails with the classic object not found error.

Changing the ACL of the object to public read/write results in the save succeeding as expected. The same behavior is present on object.destroy({useMasterKey: true}) as well.

Our understanding is the {useMasterKey:true} is supposed to override these ACL's? Are we misunderstanding the usage, or is something else happening here?

Roost avatar Oct 03 '17 12:10 Roost

{useMasterKey: true} should actually bypass the ACL's and run as the masterKey, providing logs when running with VERBOSE=1 in the environment variables, will help understanding the issue. Also, code examples will help.

flovilmart avatar Oct 03 '17 12:10 flovilmart

Here is a simple code example for deleting an object.

exports.deleteObjectWithId = function (objectId) {

    if (!objectId) {
        return Parse.Promise.error("Please supply a valid objectId");
    }

    let delObject = tableHelper.existing("Object", objectId); 
    return delObject.destroy({useMasterkey: true}).then(result => {
        return Parse.Promise.as(result);
    }, error => {
        return Parse.Promise.error(error);
    });
};

And here is the verbose logging;

verbose: REQUEST for [POST] /app/functions/userIsAdmin: {
  "userId": "PtAjE7SUQu"
} method=POST, url=/app/functions/userIsAdmin, x-parse-application-id=KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ, x-parse-rest-api-key=gnnkugnerksuith4we5ythw34euwtf65yy3t4tfni5e4w459ec8yt, x-parse-client-key=slDiwWSRaj9WD8d3w8pMju9BnbWcMIVyXi7LunFf, content-type=application/json;charset=utf-8, x-parse-session-token=r:4fd5724c7064ed5e6540915e60b8f097, host=localhost:1339, content-length=23, connection=close, userId=PtAjE7SUQu
verbose: REQUEST for [GET] /app/classes/_Role: {
  "where": {
    "name": "Administrator"
  },
  "limit": 1
} method=GET, url=/app/classes/_Role, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=318, connection=close, name=Administrator, limit=1
verbose: RESPONSE from [GET] /app/classes/_Role: {
  "response": {
    "results": [
      {
        "objectId": "YAu0REi0GQ",
        "updatedAt": "2017-10-02T09:00:54.096Z",
        "name": "Administrator",
        "createdAt": "2015-03-08T13:30:51.388Z",
        "users": {
          "__type": "Relation",
          "className": "_User"
        },
        "roles": {
          "__type": "Relation",
          "className": "_Role"
        },
        "ACL": {
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=YAu0REi0GQ, updatedAt=2017-10-02T09:00:54.096Z, name=Administrator, createdAt=2015-03-08T13:30:51.388Z, __type=Relation, className=_User, __type=Relation, className=_Role, read=true]
verbose: REQUEST for [GET] /app/classes/_User: {
  "where": {
    "$relatedTo": {
      "object": {
        "__type": "Pointer",
        "className": "_Role",
        "objectId": "YAu0REi0GQ"
      },
      "key": "users"
    },
    "objectId": "PtAjE7SUQu"
  },
  "limit": 1
} method=GET, url=/app/classes/_User, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=422, connection=close, __type=Pointer, className=_Role, objectId=YAu0REi0GQ, key=users, objectId=PtAjE7SUQu, limit=1
verbose: RESPONSE from [GET] /app/classes/_User: {
  "response": {
    "results": [
      {
        "objectId": "PtAjE7SUQu",
        "email": "[redacted]",
        "displayName": "[redacted]",
        "lowerDisplayName": "[redacted]",
        "username": "[redacted]",
        "updatedAt": "2017-10-03T09:18:54.383Z",
        "createdAt": "2016-06-10T18:08:29.266Z",
        "deleted": false,
        "signupComplete": true,
        "bot": false,
        "week": 70,
        "subscriber": true,
        "points": 46256,
        "level": 28,
        "notificationCount": 49,
        "imageUpdatedAt": {
          "__type": "Date",
          "iso": "2016-11-18T07:00:40.001Z"
        },
        "image": {
          "__type": "File",
          "name": "8bcbbcb096c83e66e5be89603919a3e5_image.jpg",
          "url": "http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg"
        },
        "privateUser": true,
        "caption": "Live well, laugh often and love many. \\ud83d\\ude21\\ud83d\\udca9\\ud83d\\ude01\\ud83d\\ude0d\\ud83d\\ude2c\\ud83c\\udf38\\ud83d\\ude0b\\ud83d\\udc4c\\u261d\\ufe0f\\ufe0f\\ud83d\\udc4c",
        "locationName": "",
        "website": "",
        "profileImageURL": "https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg",
        "followingIds": [
          "TatpuLlvaE",
          "vZjgiC3WGA",
          "YlLObpOFBQ",
          "RWe5OGLFYj",
          "R1ZPvZsi0E",
          "ADbIesozrM",
          "FvuXrL8IBw",
          "zPbu4FYXOc",
          "t1v0G6mA4h",
          "iq7ZEU5ezL",
          "ZqAlpnB3yA",
          "fGhfTz1gdr",
          "1WE7rzDrGN",
          "x8r4SS8OtQ",
          "ySS5mCI4MQ"
        ],
        "followingCount": 18,
        "sessionWorkoutCount": 110,
        "sessionCount": 154,
        "sessionExerciseCount": 74,
        "followersCount": 14,
        "expirationDate": {
          "__type": "Date",
          "iso": "2020-05-20T07:17:20.132Z"
        },
        "subscriptionActive": true,
        "userType": "promoted",
        "lastActiveDate": {
          "__type": "Date",
          "iso": "2017-08-24T17:28:04.599Z"
        },
        "userInfo": {
          "timeZone": "Europe/London",
          "intro": {
            "status": "requested"
          },
          "oxyPreferences": {
            "sessionCount": 5,
            "sessionTimeMins": 25,
            "fitnessGoal": "weight"
          }
        },
        "lastSessionDate": {
          "__type": "Date",
          "iso": "2017-10-03T09:18:54.351Z"
        },
        "userPerf": {
          "__type": "Pointer",
          "className": "UserPerf",
          "objectId": "wKqa04knjL"
        },
        "expirationDateMs": 1589959040132,
        "subscriptionRetries": 3,
        "fitTestZones": [
          {
            "zone": "cardio",
            "positionPc": 0
          },
          {
            "zone": "upper",
            "positionPc": 0
          },
          {
            "zone": "core",
            "positionPc": 0
          },
          {
            "zone": "lower",
            "positionPc": 0
          }
        ],
        "fitnessGoal": "weight",
        "iapPurchase": {
          "__type": "Relation",
          "className": "IAPPurchase"
        },
        "iapReceipt": {
          "__type": "Relation",
          "className": "IAPReceipt"
        },
        "promoCodes": {
          "__type": "Relation",
          "className": "PromoCode"
        },
        "ACL": {
          "PtAjE7SUQu": {
            "read": true,
            "write": true
          },
          "role:Administrator": {
            "read": true
          },
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=PtAjE7SUQu, email=[redacted], displayName=[redacted], lowerDisplayName=[redacted], username=[redacted], updatedAt=2017-10-03T09:18:54.383Z, createdAt=2016-06-10T18:08:29.266Z, deleted=false, signupComplete=true, bot=false, week=70, subscriber=true, points=46256, level=28, notificationCount=49, __type=Date, iso=2016-11-18T07:00:40.001Z, __type=File, name=8bcbbcb096c83e66e5be89603919a3e5_image.jpg, url=http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg, privateUser=true, caption=Live well, laugh often and love many. \ud83d\ude21\ud83d\udca9\ud83d\ude01\ud83d\ude0d\ud83d\ude2c\ud83c\udf38\ud83d\ude0b\ud83d\udc4c\u261d\ufe0f\ufe0f\ud83d\udc4c, locationName=, website=, profileImageURL=https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg, followingIds=[TatpuLlvaE, vZjgiC3WGA, YlLObpOFBQ, RWe5OGLFYj, R1ZPvZsi0E, ADbIesozrM, FvuXrL8IBw, zPbu4FYXOc, t1v0G6mA4h, iq7ZEU5ezL, ZqAlpnB3yA, fGhfTz1gdr, 1WE7rzDrGN, x8r4SS8OtQ, ySS5mCI4MQ], followingCount=18, sessionWorkoutCount=110, sessionCount=154, sessionExerciseCount=74, followersCount=14, __type=Date, iso=2020-05-20T07:17:20.132Z, subscriptionActive=true, userType=promoted, __type=Date, iso=2017-08-24T17:28:04.599Z, timeZone=Europe/London, status=requested, sessionCount=5, sessionTimeMins=25, fitnessGoal=weight, __type=Date, iso=2017-10-03T09:18:54.351Z, __type=Pointer, className=UserPerf, objectId=wKqa04knjL, expirationDateMs=1589959040132, subscriptionRetries=3, fitTestZones=[zone=cardio, positionPc=0, zone=upper, positionPc=0, zone=core, positionPc=0, zone=lower, positionPc=0], fitnessGoal=weight, __type=Relation, className=IAPPurchase, __type=Relation, className=IAPReceipt, __type=Relation, className=PromoCode, read=true, write=true, read=true, read=true]
verbose: REQUEST for [GET] /app/classes/_Role: {
  "where": {
    "name": "Administrator"
  },
  "limit": 1
} method=GET, url=/app/classes/_Role, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=265, connection=close, name=Administrator, limit=1
verbose: RESPONSE from [GET] /app/classes/_Role: {
  "response": {
    "results": [
      {
        "objectId": "YAu0REi0GQ",
        "updatedAt": "2017-10-02T09:00:54.096Z",
        "name": "Administrator",
        "createdAt": "2015-03-08T13:30:51.388Z",
        "users": {
          "__type": "Relation",
          "className": "_User"
        },
        "roles": {
          "__type": "Relation",
          "className": "_Role"
        },
        "ACL": {
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=YAu0REi0GQ, updatedAt=2017-10-02T09:00:54.096Z, name=Administrator, createdAt=2015-03-08T13:30:51.388Z, __type=Relation, className=_User, __type=Relation, className=_Role, read=true]
verbose: REQUEST for [GET] /app/classes/_User: {
  "where": {
    "$relatedTo": {
      "object": {
        "__type": "Pointer",
        "className": "_Role",
        "objectId": "YAu0REi0GQ"
      },
      "key": "users"
    },
    "objectId": "PtAjE7SUQu"
  },
  "limit": 1
} method=GET, url=/app/classes/_User, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=369, connection=close, __type=Pointer, className=_Role, objectId=YAu0REi0GQ, key=users, objectId=PtAjE7SUQu, limit=1
verbose: RESPONSE from [GET] /app/classes/_User: {
  "response": {
    "results": [
      {
        "objectId": "PtAjE7SUQu",
        "displayName": "[redacted]",
        "lowerDisplayName": "[redacted]",
        "username": "[redacted]",
        "updatedAt": "2017-10-03T09:18:54.383Z",
        "createdAt": "2016-06-10T18:08:29.266Z",
        "deleted": false,
        "signupComplete": true,
        "bot": false,
        "week": 70,
        "subscriber": true,
        "points": 46256,
        "level": 28,
        "notificationCount": 49,
        "imageUpdatedAt": {
          "__type": "Date",
          "iso": "2016-11-18T07:00:40.001Z"
        },
        "image": {
          "__type": "File",
          "name": "8bcbbcb096c83e66e5be89603919a3e5_image.jpg",
          "url": "http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg"
        },
        "privateUser": true,
        "caption": "Live well, laugh often and love many. \\ud83d\\ude21\\ud83d\\udca9\\ud83d\\ude01\\ud83d\\ude0d\\ud83d\\ude2c\\ud83c\\udf38\\ud83d\\ude0b\\ud83d\\udc4c\\u261d\\ufe0f\\ufe0f\\ud83d\\udc4c",
        "locationName": "",
        "website": "",
        "profileImageURL": "https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg",
        "followingIds": [
          "TatpuLlvaE",
          "vZjgiC3WGA",
          "YlLObpOFBQ",
          "RWe5OGLFYj",
          "R1ZPvZsi0E",
          "ADbIesozrM",
          "FvuXrL8IBw",
          "zPbu4FYXOc",
          "t1v0G6mA4h",
          "iq7ZEU5ezL",
          "ZqAlpnB3yA",
          "fGhfTz1gdr",
          "1WE7rzDrGN",
          "x8r4SS8OtQ",
          "ySS5mCI4MQ"
        ],
        "followingCount": 18,
        "sessionWorkoutCount": 110,
        "sessionCount": 154,
        "sessionExerciseCount": 74,
        "followersCount": 14,
        "expirationDate": {
          "__type": "Date",
          "iso": "2020-05-20T07:17:20.132Z"
        },
        "subscriptionActive": true,
        "userType": "promoted",
        "lastActiveDate": {
          "__type": "Date",
          "iso": "2017-08-24T17:28:04.599Z"
        },
        "userInfo": {
          "timeZone": "Europe/London",
          "intro": {
            "status": "requested"
          },
          "oxyPreferences": {
            "sessionCount": 5,
            "sessionTimeMins": 25,
            "fitnessGoal": "weight"
          }
        },
        "lastSessionDate": {
          "__type": "Date",
          "iso": "2017-10-03T09:18:54.351Z"
        },
        "userPerf": {
          "__type": "Pointer",
          "className": "UserPerf",
          "objectId": "wKqa04knjL"
        },
        "expirationDateMs": 1589959040132,
        "subscriptionRetries": 3,
        "fitTestZones": [
          {
            "zone": "cardio",
            "positionPc": 0
          },
          {
            "zone": "upper",
            "positionPc": 0
          },
          {
            "zone": "core",
            "positionPc": 0
          },
          {
            "zone": "lower",
            "positionPc": 0
          }
        ],
        "fitnessGoal": "weight",
        "iapPurchase": {
          "__type": "Relation",
          "className": "IAPPurchase"
        },
        "iapReceipt": {
          "__type": "Relation",
          "className": "IAPReceipt"
        },
        "promoCodes": {
          "__type": "Relation",
          "className": "PromoCode"
        },
        "ACL": {
          "PtAjE7SUQu": {
            "read": true,
            "write": true
          },
          "role:Administrator": {
            "read": true
          },
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=PtAjE7SUQu, displayName=[redacted], lowerDisplayName=[redacted], username=[redacted], updatedAt=2017-10-03T09:18:54.383Z, createdAt=2016-06-10T18:08:29.266Z, deleted=false, signupComplete=true, bot=false, week=70, subscriber=true, points=46256, level=28, notificationCount=49, __type=Date, iso=2016-11-18T07:00:40.001Z, __type=File, name=8bcbbcb096c83e66e5be89603919a3e5_image.jpg, url=http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg, privateUser=true, caption=Live well, laugh often and love many. \ud83d\ude21\ud83d\udca9\ud83d\ude01\ud83d\ude0d\ud83d\ude2c\ud83c\udf38\ud83d\ude0b\ud83d\udc4c\u261d\ufe0f\ufe0f\ud83d\udc4c, locationName=, website=, profileImageURL=https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg, followingIds=[TatpuLlvaE, vZjgiC3WGA, YlLObpOFBQ, RWe5OGLFYj, R1ZPvZsi0E, ADbIesozrM, FvuXrL8IBw, zPbu4FYXOc, t1v0G6mA4h, iq7ZEU5ezL, ZqAlpnB3yA, fGhfTz1gdr, 1WE7rzDrGN, x8r4SS8OtQ, ySS5mCI4MQ], followingCount=18, sessionWorkoutCount=110, sessionCount=154, sessionExerciseCount=74, followersCount=14, __type=Date, iso=2020-05-20T07:17:20.132Z, subscriptionActive=true, userType=promoted, __type=Date, iso=2017-08-24T17:28:04.599Z, timeZone=Europe/London, status=requested, sessionCount=5, sessionTimeMins=25, fitnessGoal=weight, __type=Date, iso=2017-10-03T09:18:54.351Z, __type=Pointer, className=UserPerf, objectId=wKqa04knjL, expirationDateMs=1589959040132, subscriptionRetries=3, fitTestZones=[zone=cardio, positionPc=0, zone=upper, positionPc=0, zone=core, positionPc=0, zone=lower, positionPc=0], fitnessGoal=weight, __type=Relation, className=IAPPurchase, __type=Relation, className=IAPReceipt, __type=Relation, className=PromoCode, read=true, write=true, read=true, read=true]
info: Ran cloud function userIsAdmin for user PtAjE7SUQu with:
  Input: {"userId":"PtAjE7SUQu"}
  Result: true functionName=userIsAdmin, userId=PtAjE7SUQu, user=PtAjE7SUQu
verbose: RESPONSE from [POST] /app/functions/userIsAdmin: {
  "response": {
    "result": true
  }
} result=true
verbose: REQUEST for [POST] /app/functions/deleteObjectWithId: {
  "appFn": "deleteObjectWithId",
  "objectId": "kgKE8q6uGD"
} method=POST, url=/app/functions/deleteObjectWithId, x-parse-application-id=KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ, x-parse-rest-api-key=gnnkugnerksuith4we5ythw34euwtf65yy3t4tfni5e4w459ec8yt, x-parse-client-key=slDiwWSRaj9WD8d3w8pMju9BnbWcMIVyXi7LunFf, content-type=application/json;charset=utf-8, x-parse-session-token=r:4fd5724c7064ed5e6540915e60b8f097, host=localhost:1339, content-length=56, connection=close, appFn=deleteObjectWithId, objectId=kgKE8q6uGD
verbose: REQUEST for [GET] /app/classes/_Role: {
  "where": {
    "name": "Administrator"
  },
  "limit": 1
} method=GET, url=/app/classes/_Role, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=318, x-newrelic-id=VQMDV1ZSCRADXFhVBggAUA==, x-newrelic-transaction=PxQGUVFbD1AFAlBQUwAAA1QTGlUDChAHHEAJUg8AA1EGAwhTVVAEB1QUG0MFBwsGU1AFVBVs, connection=close, name=Administrator, limit=1
verbose: RESPONSE from [GET] /app/classes/_Role: {
  "response": {
    "results": [
      {
        "objectId": "YAu0REi0GQ",
        "updatedAt": "2017-10-02T09:00:54.096Z",
        "name": "Administrator",
        "createdAt": "2015-03-08T13:30:51.388Z",
        "users": {
          "__type": "Relation",
          "className": "_User"
        },
        "roles": {
          "__type": "Relation",
          "className": "_Role"
        },
        "ACL": {
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=YAu0REi0GQ, updatedAt=2017-10-02T09:00:54.096Z, name=Administrator, createdAt=2015-03-08T13:30:51.388Z, __type=Relation, className=_User, __type=Relation, className=_Role, read=true]
verbose: REQUEST for [GET] /app/classes/_User: {
  "where": {
    "$relatedTo": {
      "object": {
        "__type": "Pointer",
        "className": "_Role",
        "objectId": "YAu0REi0GQ"
      },
      "key": "users"
    },
    "objectId": "PtAjE7SUQu"
  },
  "limit": 1
} method=GET, url=/app/classes/_User, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=422, x-newrelic-id=VQMDV1ZSCRADXFhVBggAUA==, x-newrelic-transaction=PxQGUVFbD1AFAlBQUwAAA1QTGlUDChAHHEAJUg8AA1EGAwhTVVAEB1QUG0MFBwsGU1AFVBVs, connection=close, __type=Pointer, className=_Role, objectId=YAu0REi0GQ, key=users, objectId=PtAjE7SUQu, limit=1
verbose: RESPONSE from [GET] /app/classes/_User: {
  "response": {
    "results": [
      {
        "objectId": "PtAjE7SUQu",
        "email": "[redacted]",
        "displayName": "[redacted]",
        "lowerDisplayName": "[redacted]",
        "username": "[redacted]",
        "updatedAt": "2017-10-03T09:18:54.383Z",
        "createdAt": "2016-06-10T18:08:29.266Z",
        "deleted": false,
        "signupComplete": true,
        "bot": false,
        "week": 70,
        "subscriber": true,
        "points": 46256,
        "level": 28,
        "notificationCount": 49,
        "imageUpdatedAt": {
          "__type": "Date",
          "iso": "2016-11-18T07:00:40.001Z"
        },
        "image": {
          "__type": "File",
          "name": "8bcbbcb096c83e66e5be89603919a3e5_image.jpg",
          "url": "http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg"
        },
        "privateUser": true,
        "caption": "Live well, laugh often and love many. \\ud83d\\ude21\\ud83d\\udca9\\ud83d\\ude01\\ud83d\\ude0d\\ud83d\\ude2c\\ud83c\\udf38\\ud83d\\ude0b\\ud83d\\udc4c\\u261d\\ufe0f\\ufe0f\\ud83d\\udc4c",
        "locationName": "",
        "website": "",
        "profileImageURL": "https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg",
        "followingIds": [
          "TatpuLlvaE",
          "vZjgiC3WGA",
          "YlLObpOFBQ",
          "RWe5OGLFYj",
          "R1ZPvZsi0E",
          "ADbIesozrM",
          "FvuXrL8IBw",
          "zPbu4FYXOc",
          "t1v0G6mA4h",
          "iq7ZEU5ezL",
          "ZqAlpnB3yA",
          "fGhfTz1gdr",
          "1WE7rzDrGN",
          "x8r4SS8OtQ",
          "ySS5mCI4MQ"
        ],
        "followingCount": 18,
        "sessionWorkoutCount": 110,
        "sessionCount": 154,
        "sessionExerciseCount": 74,
        "followersCount": 14,
        "expirationDate": {
          "__type": "Date",
          "iso": "2020-05-20T07:17:20.132Z"
        },
        "subscriptionActive": true,
        "userType": "promoted",
        "lastActiveDate": {
          "__type": "Date",
          "iso": "2017-08-24T17:28:04.599Z"
        },
        "userInfo": {
          "timeZone": "Europe/London",
          "intro": {
            "status": "requested"
          },
          "oxyPreferences": {
            "sessionCount": 5,
            "sessionTimeMins": 25,
            "fitnessGoal": "weight"
          }
        },
        "lastSessionDate": {
          "__type": "Date",
          "iso": "2017-10-03T09:18:54.351Z"
        },
        "userPerf": {
          "__type": "Pointer",
          "className": "UserPerf",
          "objectId": "wKqa04knjL"
        },
        "expirationDateMs": 1589959040132,
        "subscriptionRetries": 3,
        "fitTestZones": [
          {
            "zone": "cardio",
            "positionPc": 0
          },
          {
            "zone": "upper",
            "positionPc": 0
          },
          {
            "zone": "core",
            "positionPc": 0
          },
          {
            "zone": "lower",
            "positionPc": 0
          }
        ],
        "fitnessGoal": "weight",
        "iapPurchase": {
          "__type": "Relation",
          "className": "IAPPurchase"
        },
        "iapReceipt": {
          "__type": "Relation",
          "className": "IAPReceipt"
        },
        "promoCodes": {
          "__type": "Relation",
          "className": "PromoCode"
        },
        "ACL": {
          "PtAjE7SUQu": {
            "read": true,
            "write": true
          },
          "role:Administrator": {
            "read": true
          },
          "*": {
            "read": true
          }
        }
      }
    ]
  }
} results=[objectId=PtAjE7SUQu, email=[redacted], displayName=[redacted], lowerDisplayName=[redacted], username=[redacted], updatedAt=2017-10-03T09:18:54.383Z, createdAt=2016-06-10T18:08:29.266Z, deleted=false, signupComplete=true, bot=false, week=70, subscriber=true, points=46256, level=28, notificationCount=49, __type=Date, iso=2016-11-18T07:00:40.001Z, __type=File, name=8bcbbcb096c83e66e5be89603919a3e5_image.jpg, url=http://localhost:1339/app/files/KHuuXxHgNnZEJE3IMCnmz0Ta1bX2dIdnGVhW3rbZ/8bcbbcb096c83e66e5be89603919a3e5_image.jpg, privateUser=true, caption=Live well, laugh often and love many. \ud83d\ude21\ud83d\udca9\ud83d\ude01\ud83d\ude0d\ud83d\ude2c\ud83c\udf38\ud83d\ude0b\ud83d\udc4c\u261d\ufe0f\ufe0f\ud83d\udc4c, locationName=, website=, profileImageURL=https://company-staging.s3.amazonaws.com/user_uploads/3533bc48-b163-4f71-85f2-e98906e53af4_image.jpg, followingIds=[TatpuLlvaE, vZjgiC3WGA, YlLObpOFBQ, RWe5OGLFYj, R1ZPvZsi0E, ADbIesozrM, FvuXrL8IBw, zPbu4FYXOc, t1v0G6mA4h, iq7ZEU5ezL, ZqAlpnB3yA, fGhfTz1gdr, 1WE7rzDrGN, x8r4SS8OtQ, ySS5mCI4MQ], followingCount=18, sessionWorkoutCount=110, sessionCount=154, sessionExerciseCount=74, followersCount=14, __type=Date, iso=2020-05-20T07:17:20.132Z, subscriptionActive=true, userType=promoted, __type=Date, iso=2017-08-24T17:28:04.599Z, timeZone=Europe/London, status=requested, sessionCount=5, sessionTimeMins=25, fitnessGoal=weight, __type=Date, iso=2017-10-03T09:18:54.351Z, __type=Pointer, className=UserPerf, objectId=wKqa04knjL, expirationDateMs=1589959040132, subscriptionRetries=3, fitTestZones=[zone=cardio, positionPc=0, zone=upper, positionPc=0, zone=core, positionPc=0, zone=lower, positionPc=0], fitnessGoal=weight, __type=Relation, className=IAPPurchase, __type=Relation, className=IAPReceipt, __type=Relation, className=PromoCode, read=true, write=true, read=true, read=true]
verbose: REQUEST for [DELETE] /app/classes/Workout/kgKE8q6uGD: {} method=DELETE, url=/app/classes/Workout/kgKE8q6uGD, user-agent=node-XMLHttpRequest, Parse/js1.10.0 (NodeJS 6.9.1), accept=*/*, content-type=text/plain, host=localhost:1339, content-length=225, x-newrelic-id=VQMDV1ZSCRADXFhVBggAUA==, x-newrelic-transaction=PxQGUVFbD1AFAlBQUwAAA1QTGlUDChAHHEAJUg8AA1EGAwhTVVAEB1QUG0MFBwsGU1AFVBVs, connection=close, 
error: Error generating response. ParseError { code: 101, message: 'Object not found.' } code=101, message=Object not found.
error: Object not found. code=101, message=Object not found.
error: Failed running cloud function deleteObjectWithId for user PtAjE7SUQu with:
  Input: {"appFn":"deleteObjectWithId","objectId":"kgKE8q6uGD"}
  Error: {"code":141,"message":{"code":101,"message":"Object not found."}} functionName=deleteObjectWithId, code=141, code=101, message=Object not found., appFn=deleteObjectWithId, objectId=kgKE8q6uGD, user=PtAjE7SUQu
error: Error generating response. ParseError {
  code: 141,
  message: ParseError { code: 101, message: 'Object not found.' } } code=141, code=101, message=Object not found.
error: ParseError { code: 101, message: 'Object not found.' } code=141, code=101, message=Object not found.

Roost avatar Oct 03 '17 13:10 Roost

For completeness, here is a snippet of the corresponding save function that is also failing.

let promises = [];
result.forEach(workout => {

    workout.set({published: false});
    let p1 = workout.save(null, {useMasterkey: true});

    promises.push(p1);
});

return Parse.Promise.when(promises)

Roost avatar Oct 03 '17 13:10 Roost

where are you running this code (not in cloud code IIUC) ? Did you initialize your JS SDK with the masterKey?

flovilmart avatar Oct 03 '17 13:10 flovilmart

Yes, masterKey is indeed initialised, and I validated it was actually working by testing a launch without it, and I get the expected error You must provide a masterKey!

Additionally, query.find({useMasterKey: true}) works as expected too, so I am pretty confident this isn't the issue.

Roost avatar Oct 03 '17 13:10 Roost

Interestingly, calling a separate function from a Parse.Cloud.afterDelete callback works as expected with the following code, even though the objects being destroyed only have public read ACL's

Parse.Object.destroyAll(workoutDetails, {

    useMasterKey: true,
    success: function() {},
    error: function(error) {
        console.error("Error deleting related workoutDetails " + error.code + ": " + error.message);
    }
});

Roost avatar Oct 03 '17 14:10 Roost

let promises = [];
result.forEach(workout => {

    workout.set({published: false});
    let p1 = workout.save(null, {useMasterkey: true});

    promises.push(p1);
});

return Parse.Promise.when(promises)

There is a typo in useMasterkey the K is not capitalized.

flovilmart avatar Oct 23 '17 02:10 flovilmart

@flovilmart you are indeed correct. The number of times I re-read my code to make sure I had no typo's. Sigh.

Thanks.

Roost avatar Nov 21 '17 09:11 Roost