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

Using includeKey: on array of pointers results in error

Open N4tr0n opened this issue 10 years ago • 29 comments

For implementation related questions or technical support, please refer to the Stack Overflow and Server Fault communities.

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!

Environment Setup

Local

Xcode 7.3 iPhone 6s simulator with iOS 9.3 Parse-iOS-SDK 1.13

Remote

heroku/nodejs parse-server 2.2.4 parse 1.8.1

Steps to reproduce

Precondition: There exists an object on the database that has an array of pointers as one of its fields.

  1. Create a PFQuery on the object's type.
  2. Try to include the array of pointers field using includeKey:
  3. Execute the query.

Note: This works correctly my Parse hosted app. It only becomes an issue when I try to use my parse-server hosted on heroku.

Logs/Trace

[Error]: can only include pointer fields (Code: 102, Version: 1.13.0)

N4tr0n avatar Mar 31 '16 01:03 N4tr0n

What do you expect to happen? Have the pointers loaded from the array? Or just not having an error?

flovilmart avatar Mar 31 '16 03:03 flovilmart

I expect it to load the pointers from the array. This is how it works on the Parse hosted app and what the documentation says to do.

N4tr0n avatar Mar 31 '16 15:03 N4tr0n

Alrighty!

flovilmart avatar Mar 31 '16 15:03 flovilmart

I just tried to reproduce the error and I can't reproduce it.

flovilmart avatar Mar 31 '16 23:03 flovilmart

Ok, here's a sample array

[
    {
        "__type": "Pointer",
        "className": "CustomClassName",
        "objectId": "yAj8sBKbWn"
    },
    {
        "__type": "Pointer",
        "className": "CustomClassName",
        "objectId": "VYce892Y3A"
    }
]

Where CustomClassName refers to the same class in both instances. Does this look correct?

N4tr0n avatar Mar 31 '16 23:03 N4tr0n

Can you check the commit that is referenced here and tell me if that embodies your issue?

flovilmart avatar Mar 31 '16 23:03 flovilmart

Any news on that?

flovilmart avatar Apr 04 '16 01:04 flovilmart

It looks like it may fix my issue but I have only been able to successfully set up parse-server using the 2.2.4 release on npm so I haven't been able to test the referenced commit.

Note: I tried setting up my package.json using this but I couldn't get it to work. Node kept reporting that parse-server couldn't be found.

N4tr0n avatar Apr 04 '16 01:04 N4tr0n

Yeah, you can't set it up like that as the git repository don't hold the lib. If 2.2.4 fixes your issue, that's all good then, I can close the issue. Reopen if you feel there's still a problem

flovilmart avatar Apr 04 '16 01:04 flovilmart

I meant that 2.2.4 is the latest version that I was able to install successfully and it doesn't contain the commit you referenced so I haven't been able to test the fix. The issue still exists in 2.2.4.

N4tr0n avatar Apr 04 '16 13:04 N4tr0n

Oh right. I'll reopen then and we'll see when 2.2.5 is out

flovilmart avatar Apr 04 '16 14:04 flovilmart

Ok. Thanks @flovilmart, I appreciate your help.

N4tr0n avatar Apr 04 '16 14:04 N4tr0n

2.2.5 is out! have it a go and let us know!

flovilmart avatar Apr 05 '16 02:04 flovilmart

No luck. I installed 2.2.5 but I'm still getting the same error. I'm trying to think of things that might help with troubleshooting. I'll comment here if I come up with anything.

N4tr0n avatar Apr 05 '16 17:04 N4tr0n

If you look at the test case here, that seem exactly what you're describing

flovilmart avatar Apr 05 '16 17:04 flovilmart

Yeah, it seems like it should work but I keep getting the error. I decided to run parse-server from master locally using the instructions here and this is the log output when I run the query in question:

verbose: GET /parse/classes/_User { host: 'localhost:1337',
  'x-parse-client-version': 'i1.13.0',
  accept: '*/*',
  'x-parse-session-token': 'sessionToken',
  'x-parse-application-id': 'appId',
  'x-parse-client-key': 'clientKey',
  'x-parse-installation-id': 'installationId',
  'x-parse-os-version': '9.3 (15E65)',
  'accept-language': 'en-us',
  'accept-encoding': 'gzip, deflate',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '251',
  'user-agent': 'MyApp/995 CFNetwork/758.3.15 Darwin/15.4.0',
  connection: 'keep-alive',
  'x-parse-app-build-version': '995',
  'x-parse-app-display-version': '3.0.1' } {
  "where": {
    "typeOfUser": "aUserType",
    "approved": true,
    "anArrayOfPointers": {
      "$exists": true
    },
    "location": {
      "$exists": true,
      "$nearSphere": {
        "__type": "GeoPoint",
        "longitude": xxx,
        "latitude": xxx
      }
    }
  },
  "include": "anArrayOfPointers",
  "limit": "1000"
}
verbose: error: code=102, message=can only include pointer fields

N4tr0n avatar Apr 05 '16 19:04 N4tr0n

Check the _SCHEMA class and find the _User row... Is the column you're including definitely an array column?

gfosco avatar Apr 05 '16 19:04 gfosco

Just checked and it's definitely an array. This is what it looks like:

{
    "_id": "_User",
    ...
    "anArrayOfPointers": "array",
    ...
}

N4tr0n avatar Apr 05 '16 20:04 N4tr0n

Can you check where the can only include pointer fields occurs? it's at 2 places in src/RestQuery.js

flovilmart avatar Apr 05 '16 22:04 flovilmart

Looks like the error occurs in the second case:

if (path.length == 0) {
    if (object.__type == 'Pointer') {
        return [object];
    }
    throw new Parse.Error(Parse.Error.INVALID_QUERY,
                          'can only include pointer fields');
}

More specifically, object.__type is undefined so that's why the error is thrown. Not sure why it would be undefined though.

N4tr0n avatar Apr 05 '16 23:04 N4tr0n