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

matchesQuery on relation query always finds zero objects

Open jgaull opened this issue 10 years ago • 28 comments

Environment Setup

parse-server 2.1.6, Heroku, MongoLab, iOS SDK 1.12.0

Steps to reproduce

var relationQuery = object.relation("relationKey").query();
var anotherQuery = new Parse.Query(Class);
anotherQuery.matchesQuery("key", relationQuery);
anotherQuery.find(); //Always finds 0 objects

This works correctly in hosted Parse. I also manually double-checked the db and can confirm this should find more than zero objects.

Logs/Trace

This error is showing up on the iOS side. May or may not be related: [Error]: Response status code was unacceptable: 403 (Code: 1, Version: 1.12.0)

jgaull avatar Mar 13 '16 19:03 jgaull

same problem here - parse server 2.1.6, we have an android app that uses below methods in query and previously works(with hosted parse) but at this time non of them works correctly:

whereMatchesQuery
whereMatchesKeyInQuery
whereDoesNotMatchQuery
whereDoesNotMatchKeyInQuery

Mahdi7s avatar Mar 13 '16 21:03 Mahdi7s

@jgaull please see that gist does that reflect your failing cases?

flovilmart avatar Mar 14 '16 16:03 flovilmart

Thanks @flovilmart! The only difference I can find is relationQuery.equalTo('even', true);. This can be found on lines 37 and 53. In my example the relation is used without adding any additional restrictions.

I will test today to see if adding a condition to my relation query makes it work.

jgaull avatar Mar 14 '16 17:03 jgaull

@jgaull I added the restrictions to make sure I'd get the proper subset. Maybe the bug is when no parameters are passed. I'll try it also

flovilmart avatar Mar 14 '16 18:03 flovilmart

@flovilmart I added relationQuery.equalTo("booleanProperty", true) and ensured that "booleanProperty" was set to true on every object in the relation. I got the same result: no objects found. Must be something else.

Thanks for the help! Let me know if you have an idea for something else to test.

jgaull avatar Mar 14 '16 19:03 jgaull

uhm... Do you have ACL, class level permissions or anything else set? If you run the query as master, what does it do?

Does the object structure match what you have in the app in terms of relation, key etc...

Can you show me the schema as well?

flovilmart avatar Mar 14 '16 19:03 flovilmart

ACL is default for _User object, public read and only the user has write. I am running the query as master using useMasterKey() in cloud code.

jgaull avatar Mar 14 '16 19:03 jgaull

and the related objects are _Users ?

flovilmart avatar Mar 14 '16 19:03 flovilmart

Correct

jgaull avatar Mar 14 '16 19:03 jgaull

I really can't reproduce the error. Can you dump me the _SCHEMA collection from mongoDB?

flovilmart avatar Mar 14 '16 20:03 flovilmart

TBH, I'm out of ideas now, are you running it in Cloud Code? Parse.Cloud.useMasterKey() don't work, you have to pass {useMasterKey: true} to your query.find(). Does it help?

flovilmart avatar Mar 14 '16 21:03 flovilmart

Thanks @flovilmart! I tried {useMasterKey: true} and there was no change.

Here is a link to my _SCHEMA dump.

jgaull avatar Mar 14 '16 23:03 jgaull

on which classes do you do your queries?

flovilmart avatar Mar 14 '16 23:03 flovilmart

Sorry, definitely should have included that info.

I'm using the "members" relation in Group to query for UserWeeklyStats in one place and Rides in another. Both find zero objects.

jgaull avatar Mar 14 '16 23:03 jgaull

Does the relation query itself returns some values? Can you try to split the query in 2? relationQuery first, get the objects and do a containedIn? ThatMs tough as I can't reproduce the issue at all...

flovilmart avatar Mar 15 '16 00:03 flovilmart

I have tested splitting the query into two pieces. Both work independently as expected.

One thought I had was that, since this is my dev DB, some _Users have been deleted at various points during development. The relation probably still holds a reference to those deleted _Users. Is it possible that that's causing the query to break?

jgaull avatar Mar 15 '16 00:03 jgaull

Tried deleting objects in the middle, and it behaves correctly, so the deletion doesn't seem to be the problem.

flovilmart avatar Mar 15 '16 01:03 flovilmart

Can you set VERBOSE=1 on heroku (https://devcenter.heroku.com/articles/config-vars), and make a gist with the request logs ??

the interesting lines should be similar to:

GET /1/classes/AnOwner { 'user-agent': 'node-XMLHttpRequest, Parse/js1.7.1 (NodeJS 5.3.0)',
  accept: '*/*',
  'content-type': 'text/plain',
  host: 'localhost:8378',
  'content-length': '357',
  connection: 'close' } {
  "where": {
    "key": {
      "$inQuery": {
        "where": {
          "$relatedTo": {
            "object": {
              "__type": "Pointer",
              "className": "AnotherOwner",
              "objectId": "PBqgHRHCNd"
            },
            "key": "relationKey"
          },
          "even": true
        },
        "className": "AnObject"
      }
    }
  },
  "include": "key"
}

flovilmart avatar Mar 15 '16 01:03 flovilmart

Does that look familiar? https://github.com/ParsePlatform/parse-server/issues/1036#issuecomment-196792097

flovilmart avatar Mar 15 '16 12:03 flovilmart

Thanks @flovilmart! I imported using the Parse migration tool from the beginning so I don't think I'm experiencing the same issue.

Here is a gist with the log you asked for.

jgaull avatar Mar 15 '16 18:03 jgaull