parse-server: Parse.Query.find() returns Parse.Pointer[] instead of Parse.Object[]

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);

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 50 (42 by maintainers)

Commits related to this issue

Most upvoted comments

@dplewis @davimacedo @mtrezza I’m going to pick this one up as I “think” ran into a similar issue while testing Parse-Swift and I think I know how to replicate it.

  1. The issue occurs on mongo and postgres
  2. To replicate, I create a ParseObject that that contains a Pointer field, and a Pointer array field.
  3. The following scenarios work or are broken
  • includeAll (broken) - will only return all pointers
  • include["PointerFieldKey"] (works) - will return the actual object
  • include["PointerArrayFieldKey"](works) - will return the array of actual objects
  • include["PointerFieldKey", "PointerArrayFieldKey"](broken) - will return the actual object of PointerFieldKey, but return pointers to PointerArrayFieldKey

I’ll open a PR later today with a failing test case and hopefully a fix (I haven’t investigated where the problem is yet). If you have any leads, let me know

I’m following your lead @davimacedo and it turns out that the request works fine when I don’t register the subclass Profile.

// Parse.Object.registerSubclass('Profile', Profile); // <-- When I comment this line it all (sort of) works fine