Repository navigation
ParseObject attributes of the ParseObject in afterSave/beforeSave triggers aren't valid for using in queries. #2000
Description
In an afterSave trigger I get an attribute that is ParseObject request.object.get('pointerToOtherParseObject'). I then use that object in a query and get this error: You cannot use [object Object] as a query parameter.
If I convert the object that was an attribute to the triggered object to a new ParseObject everything works as normal.
On the Parse.com hosted service I can use these attributes for performing a query.
Steps to reproduce
Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.
Trigger Setup
- Create an afterSave trigger function for "Comment".
- In the function get an attribute that is a Pointer to another ParseObject ("Post")
- Use that Object in an query.
Parse.Cloud.afterSave("Comment", function(request) {
var post = request.object.get("post");
var query = new Parse.Query("DailyPostCommentCount");
query.equalTo("dayInt",20160607);
console.log(post);
query.equalTo("post",post);
query.first().then(function(commentCount) {
console.log("successfully found the object that we want to update");
commentCount.increment("count");
return commentCount.save();
}).then(function(savedCommentCount) {
console.log("saved comment count");
},function(error) {
console.log("failed to find the object and update it with error:");
console.log(error);
});
});Environment Setup
- Use Rest API to create a 'Post'
- Use Rest API to create a 'DailyPostCommentCount'
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: , <RestKey>" \
-H "Content-Type: application/json" \
-d '{"title":"I am Hungry","content":"Where should we go for lunch"}' \
http://localhost:1337/parse/classes/Post
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: <RestKey>" \
-H "Content-Type: application/json" \
-d '{"dayInt":20160607,"post":{"__type":"Pointer","className":"Post","objectId":"objecIdFromFirstRestCall"}}' \
http://localhost:1337/parse/classes/DailyPostCommentCount
Hitting the trigger
- Use Rest API to create a 'Comment' and trigger afterSave Function
curl -X POST \
-H "X-Parse-Application-Id: <appId>" \
-H "X-Parse-REST-API-Key: <RestKey>" \
-H "Content-Type: application/json" \
-d '{"content":"How about Sushirrito", "post":{"__type":"Pointer","className":"Post","objectId":"objecIdFromFirstRestCall"}}' \
http://localhost:1337/parse/classes/Comment
Expected Results
THe DailyPostCommentCount to increment 'count' counter.
Actual Outcome
ParseObject { _objCount: 1, className: 'Post', id: 'EJz6jexLbL' }
failed to find the object and update it with error:
ParseError {
code: 107,
message: 'You cannot use [object Object] as a query parameter.' }
If I convert the object to new ParseObject of the correct class everything works as normal:
exports.parseObjectFromParseDictObject = function(dict) {
var ObjectClass = Parse.Object.extend(dict.className);
var newObject = new ObjectClass();
newObject.id = dict.id;
return newObject;
}
Environment Setup
-
Server
- parse-server version: 2.2.11
- Operating System: OSX El Capitan
- Hardware: MacBook Pro
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Localhost
Same result when tried on Heroku
-
Database
- MongoDB version: 3.0.9
- Storage engine: MMAP
- Hardware: ?
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): ObjectRocket
Logs/Trace
You can turn on additional logging by configuring VERBOSE=1 in your environment.
10:11:01 web.1 | verbose: POST /parse/classes/Comment { host: 'localhost:1337',
10:11:01 web.1 | 'user-agent': 'curl/7.43.0',
10:11:01 web.1 | accept: '*/*',
10:11:01 web.1 | 'x-parse-application-id': 'adsfasdf',
10:11:01 web.1 | 'x-parse-rest-api-key': 'asdfas',
10:11:01 web.1 | 'content-type': 'application/json',
10:11:01 web.1 | 'content-length': '106' } {
10:11:01 web.1 | "content": "How about Sushirrito",
10:11:01 web.1 | "post": {
10:11:01 web.1 | "__type": "Pointer",
10:11:01 web.1 | "className": "Post",
10:11:01 web.1 | "objectId": "EJz6jexLbL"
10:11:01 web.1 | }
10:11:01 web.1 | }
10:11:02 web.1 | ParseObject { _objCount: 1, className: 'Post', id: 'EJz6jexLbL' }
10:11:02 web.1 | verbose: {
10:11:02 web.1 | "status": 201,
10:11:02 web.1 | "response": {
10:11:02 web.1 | "objectId": "ntAEASQLm7",
10:11:02 web.1 | "createdAt": "2016-06-07T16:11:01.580Z"
10:11:02 web.1 | },
10:11:02 web.1 | "location": "http://localhost:1337/parse/classes/Comment/ntAEASQLm7"
10:11:02 web.1 | }
10:11:02 web.1 | verbose: GET /parse/classes/DailyPostCommentCount { 'user-agent': 'node-XMLHttpRequest, Parse/js1.6.14 (NodeJS 4.4.0)',
10:11:02 web.1 | accept: '*/*',
10:11:02 web.1 | 'content-type': 'text/plain',
10:11:02 web.1 | host: 'localhost:1337',
10:11:02 web.1 | 'content-length': '320',
10:11:02 web.1 | connection: 'close' } {
10:11:02 web.1 | "where": {
10:11:02 web.1 | "dayInt": 20160607,
10:11:02 web.1 | "post": {
10:11:02 web.1 | "_objCount": 1,
10:11:02 web.1 | "className": "Post",
10:11:02 web.1 | "id": "EJz6jexLbL"
10:11:02 web.1 | }
10:11:02 web.1 | },
10:11:02 web.1 | "limit": 1
10:11:02 web.1 | }
10:11:02 web.1 | verbose: error: code=107, message=You cannot use [object Object] as a query parameter.
10:11:02 web.1 | failed to find the object and update it with error:
10:11:02 web.1 | ParseError {
10:11:02 web.1 | code: 107,
10:11:02 web.1 | message: 'You cannot use [object Object] as a query parameter.' }
Activity
zingano commentedon Jun 9, 2016
I think I am seeing something related but a different error - I'm getting {"code":119,"message":"Permission denied for this action."}
I have an Account, which has an owning Customer. In the afterSave I want to update the count of Accounts in the Customer and add the Account to the Customer's array of Accounts.
My afterSave for Account is:
The logs for these show at even after fetching, the Customer name and numberOfAccounts are undefined.
Both Customer and Account are only accessible to a role called Admin. The calling user (me) is a member of that Role.
zingano commentedon Jun 9, 2016
In my code above, rather than fetching the Customer, I've tried doing a query like this: query.equalTo("objectId", customer.id);
The Customer that is returned is in the same state as above - members are undefined.
zingano commentedon Jun 9, 2016
After doing some debugging in the Parse Server code that's returning my error, I think I'm getting that permissions fail because that class doesn't have "addField" permission. However, this code is not adding a field - I suspect Parse Server thinks that because the object is improperly fetched and its fields are undefined.
hramos commentedon Jul 27, 2016
We're closing this issue due to inactivity.
If this is a bug you care about that is not getting attention, consider opening a pull request with a fix.
zingano commentedon Jul 28, 2016
But the inactivity's from your side! In that case surely it should stay open?
shankslouis commentedon Dec 8, 2016
@zingano did you solve the ParseError 119? thrown in your afterSave function?