Parse-server: Using includeKey: on array of pointers results in error

Created on 31 Mar 2016  路  29Comments  路  Source: parse-community/parse-server

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)

troubleshooting

Most helpful comment

Hello, same error we see here. An array of PFObjects are only returning partial data instead of full, even with includeKey. It works fine with just a single pointer however.

All 29 comments

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

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.

Alrighty!

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

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?

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

Any news on that?

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.

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

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.

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

Ok. Thanks @flovilmart, I appreciate your help.

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

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.

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

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

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

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

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

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

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.

try console.log the object?

Here's the log of the object: { objectId: 'mpImkB2Zyw' } Don't know why the __type and className fields aren't there.

Maybe because they have been improperly stored... Are all your objects like that? What's your client code that creates those objects? try removing the throwing, and ignore the unproperly configured objects by returning an empty array, see if many/most of those are improperly stored.

Yeah, that was the problem. I remember we had some issues with this array when adding a web client. Anyway, I found two users that had bad arrays. After I removed the bad arrays the query worked perfectly. I guess on the Parse hosted apps the bad arrays are ignored.

Thanks again for all your help, it is truly appreciated.

May be, let's close that for now.

I have the same problem with arrays of PFUsers and PFFIles.
What should I do, rewrite the code so as to avoid this type of arrays or wait for this problem to solved?
Is the problem being addressed so that we can expect it to be solved?

I am also getting arrays of pointers like this in my database sometimes:
[{"objectId":"9m2llSTANa"},{"objectId":"Rtu7IEU9cT"}]

Instead of
[{"__type":"Pointer","className":"_User","objectId":"1Nii4IsZc1"},{"__type":"Pointer","className":"_User","objectId":"Glivar389e"}]

In a query when I do this query.includeKey("users") I get no results. When I remove this includeKey I get results but without the users objects of course (I mean, no data available). This is my full query:

let query = Chat.query()!
query.whereKey("users", equalTo: user)
query.includeKey("users")

Funny how if I remove that whereKey I get error _can only include pointer fields_.

Hello, same error we see here. An array of PFObjects are only returning partial data instead of full, even with includeKey. It works fine with just a single pointer however.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ViolentCrumble picture ViolentCrumble  路  3Comments

dpaid picture dpaid  路  3Comments

jaydeep82 picture jaydeep82  路  4Comments

lorki picture lorki  路  3Comments

dcdspace picture dcdspace  路  3Comments