parse-community / parse-community/parse-server
Parse.Query.find() returns Parse.Pointer[] instead of Parse.Object[]
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
Issue Description
When running a simple query on a class from cloud code, the result is an array of pointers to class objects instead of an array of actual objects. When the same query is run on the client it works ok.
This only happens on a specific class (Profile in my case), the same query on any other class returns the expected output.
Steps to reproduce
Call this cloud function function for a certain class (in this case Profile):
Parse.Cloud.define('department:getMembers', request => {
return new Parse.Query(Profile).find({useMasterKey: true});
});
Expected Results
If I run the same query from the client: new Parse.Query(Profile).find();, what I get is a list of Parse Objects as expected:
{
"results": [
{
"objectId": "SmAkS6KX9F",
"accreditations": [
{
"code": 5,
"year": 2013
}
],
"awards": [
{
"name": "gdsf",
"awardedBy": "dsgf",
"year": 2004,
"details": "hfgdfdhgdfhg"
}
],
// more properties...
},
{
"objectId": "MhOASa4bBa",
"accreditations": [],
"awards": [],
// more properties...
},
{
"objectId": "yIIEz9UIGp",
"accreditations": [],
"awards": [],
// more properties...
}
]
}
Actual Outcome
... but when run from cloud code I'm getting just pointers instead of actual objects!:
{
"result": [
{
"__type": "Pointer",
"className": "Profile",
"objectId": "SmAkS6KX9F"
},
{
"__type": "Pointer",
"className": "Profile",
"objectId": "MhOASa4bBa"
},
{
"__type": "Pointer",
"className": "Profile",
"objectId": "yIIEz9UIGp"
}
]
}
Environment Setup
-
Server
- parse-server version (Be specific! Don't say 'latest'.) : 3.1.1
- Operating System: Win10
- Hardware: Intel Core i5-6200U; RAM 12GB
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Local
-
Database
- MongoDB version: v4.0.1
- Storage engine: WiredTiger
- Hardware: (same as server) Intel Core i5-6200U; RAM 12GB
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Local
Logs/Trace
info: Ran cloud function department:getMembers for user rhLnSgyBQv with:
Input: {"department":{"__type":"Pointer","className":"Department","objectId":"nBcxb3juBx"}}
Result: [{"__type":"Pointer","className":"Profile","objectId":"SmAkS6KX9F"},{"__type":"Pointer","className":"Profile","objectId":"MhOASa4bBa"},{"__type":"Pointer","className":"Profile","objectId":"yIIEz9UIGp"}] functionName=department:getMembers, __type=Pointer, className=Department, objectId=nBcxb3juBx, user=rhLnSgyBQv
verbose: RESPONSE from [POST] /scope/functions/department:getMembers: {
"response": {
"result": [
{
"__type": "Pointer",
"className": "Profile",
"objectId": "SmAkS6KX9F"
},
{
"__type": "Pointer",
"className": "Profile",
"objectId": "MhOASa4bBa"
},
{
"__type": "Pointer",
"className": "Profile",
"objectId": "yIIEz9UIGp"
}
]
}
} result=[__type=Pointer, className=Profile, objectId=SmAkS6KX9F, __type=Pointer, className=Profile, objectId=MhOASa4bBa, __type=Pointer, className=Profile, objectId=yIIEz9UIGp]
Some more code
For what it's worth, this is the code for the class Profile.ts.
import Parse from '@parse';
import { User } from '@library/user/user';
// some more imports...
export class Profile extends Parse.Object {
constructor(attributes?: IProfile) {
super('Profile', attributes);
this.accreditations = attributes && attributes.accreditations || [];
this.awards = attributes && attributes.awards || [];
this.seniority = attributes && attributes.seniority || [];
this.degrees = attributes && attributes.degrees || [];
}
get user(): User { return this.get('user'); }
set user(val: User) { this.set('user', val); }
// some more setters and functions...
toJSON(): IProfile {
const json = super.toJSON();
json.photoUrl = this.photoUrl;
return json;
}
}
// IMPORTANT: Register as Parse subclass
Parse.Object.registerSubclass('Profile', Profile);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the department:getMembers cloud function with Parse Server 3.1.1 and compare its Parse.Query(Profile).find() result with the client query. Review Profile.ts, including its Parse.Object subclass registration and toJSON implementation, then identify why cloud-code results serialize as pointers; done means the cloud query returns full Profile objects like the client query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100