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

exists query seems to give error #36

Closed
Enalmada opened this issue Apr 10, 2014 · 6 comments
Closed

exists query seems to give error #36

Enalmada opened this issue Apr 10, 2014 · 6 comments

Comments

@Enalmada
Copy link
Contributor

When I try and use exists filter, I get bad type for $exists. I assume I should be doing __exists='false'. Totally sorry if this is not supported or I am trying to use the exists filter wrong. I figured it would be either __exists='false' or __exists=false based on my best reading of the docs.

I am trying to find all users with a publisherId of 15 that have LoggedIn as (undefined).

Sample...

users = list(User.Query.filter(publisherId='15').filter(LoggedIn__exists='false').limit(1000))

Error when I do __exists='false'

Traceback (most recent call last):
  File "./parse_user_update_test.py", line 36, in <module>
    users = list(User.Query.filter(publisherId='15').filter(LoggedIn__exists='false').limit(1000).order_by("LoggedIn", descending=False))
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parse_rest/query.py", line 102, in __iter__
    return iter(self._fetch())
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parse_rest/query.py", line 117, in _fetch
    return self._manager._fetch(**options)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parse_rest/query.py", line 41, in _fetch
    return [klass(**it) for it in klass.GET(uri, **kw).get('results')]
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parse_rest/connection.py", line 108, in GET
    return cls.execute(uri, 'GET', **kw)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/parse_rest/connection.py", line 102, in execute
    raise exc(e.read())
parse_rest.core.ResourceRequestBadRequest: {"code":102,"error":"bad type for $exists"}

Error when i do __exists=false

Traceback (most recent call last):
  File "./parse_user_update_test.py", line 36, in <module>
    users = list(User.Query.filter(publisherId='15').filter(LoggedIn__exists=false).limit(1000).order_by("LoggedIn", descending=False))
NameError: name 'false' is not defined

Raw example from REST API https://www.parse.com/docs/rest#queries-constraints

curl -X GET \
  -H "X-Parse-Application-Id: v8ZPeTW4nKEHDmmaU6eJUiF2s3tE16yrYZzGzipR" \
  -H "X-Parse-REST-API-Key: 3hT7widAIBwKx3N3vcqCVU9P0CN2WCCKZ16ex7vD" \
  -G \
  --data-urlencode 'where={"score":{"$exists":true}}' \
  https://api.parse.com/1/classes/GameScore

Thanks again for such a great library.

@dgrtwo
Copy link
Collaborator

dgrtwo commented Apr 10, 2014

Hi Enalmada: I can't quite reproduce the error yet, but let me ask: your traceback shows the line

users = list(User.Query.filter(publisherId='15').filter(publisherId__exists='true').limit(1000).order_by("LoggedIn", descending=False))

Why filter for publisherId existing after already filtering for publisherId equaling 15?

@Enalmada
Copy link
Contributor Author

You have good eyes. I was actually manipulating my existing workaround code so I could provide you an exact stacktrace. As a workaround I found that if I sort by descending false, then all the non-exist fields go to the top but makes the code smell so I figured I would look harder into getting exists working. Thanks for your help on this.

@Enalmada
Copy link
Contributor Author

So I updated the issue with my exact real code I am trying to run. I was trying to simplify the test case which usually is a good idea but I just realized that the error is different with my full intended code. Doh. Sorry. Hopefully this error is actually easier to reproduce.

@dgrtwo
Copy link
Collaborator

dgrtwo commented Apr 10, 2014

Change to __exists=False

@Enalmada
Copy link
Contributor Author

Oh man you are right! Silly me. Thanks very much for helping me. I had a feeling I was doing something wrong on this one.

@dgrtwo
Copy link
Collaborator

dgrtwo commented Apr 11, 2014

No problem: In fact your query illuminated an important failure mode (filtering for a constraint after filtering for a specific value) that I just added an informative error message for in 728c492. Thanks for your issue!

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

No branches or pull requests

2 participants