Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matchesQuery on relation query always finds zero objects #1014

Closed
jgaull opened this issue Mar 13, 2016 · 28 comments · Fixed by #1046
Closed

matchesQuery on relation query always finds zero objects #1014

jgaull opened this issue Mar 13, 2016 · 28 comments · Fixed by #1046

Comments

@jgaull
Copy link

jgaull commented Mar 13, 2016

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)

@Mahdi7s
Copy link

Mahdi7s commented Mar 13, 2016

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

@flovilmart
Copy link
Contributor

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

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

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.

@flovilmart
Copy link
Contributor

@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

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

@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.

@flovilmart
Copy link
Contributor

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?

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

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.

@flovilmart
Copy link
Contributor

and the related objects are _Users ?

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

Correct

@flovilmart
Copy link
Contributor

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

@flovilmart
Copy link
Contributor

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?

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

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

Here is a link to my _SCHEMA dump.

@flovilmart
Copy link
Contributor

on which classes do you do your queries?

@jgaull
Copy link
Author

jgaull commented Mar 14, 2016

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.

@flovilmart
Copy link
Contributor

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...

@jgaull
Copy link
Author

jgaull commented Mar 15, 2016

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?

@flovilmart
Copy link
Contributor

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

@flovilmart
Copy link
Contributor

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
Copy link
Contributor

Does that look familiar? #1036 (comment)

@jgaull
Copy link
Author

jgaull commented Mar 15, 2016

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.

@flovilmart
Copy link
Contributor

I see that there is the startOfWeek parameter too in the query, does removing it solves the issue?

@jgaull
Copy link
Author

jgaull commented Mar 15, 2016

@flovilmart
Copy link
Contributor

We identified the issue, and working on a fix.
in the meantime, you should be able to work around by fetching the object you're calling .relation('relationKey') on.

@jgaull
Copy link
Author

jgaull commented Mar 15, 2016

Nice work! Thanks so much for your help!

@flovilmart
Copy link
Contributor

You should thank @gfosco ! the was the brains :)

@awgeorge
Copy link
Contributor

Any chance this has snuck back into 2.3.6? matchesKeyInQuery is always returning an empty set.

@flovilmart
Copy link
Contributor

We usually don't remove tests, in order to prevent regressions. Can you open a new issue as it's been closed a while ago?

@dipeshparashar
Copy link

dipeshparashar commented Aug 26, 2020

The same issue. MatchesQuery works in Swift but not in JS.
https://github.com/parse-community/parse-server/issues/6883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants