pyeve / eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
http://eve-sqlalchemy.readthedocs.io
Other
234 stars 70 forks source link

Query expression doesn't work #127

Open nagarajgond opened 7 years ago

nagarajgond commented 7 years ago

Hi,

Below expression doesn't work when I tried eve with eve_sqlalchemy for MySQL. http://127.0.0.1:5001/activity?where={"status":"Ok"}

but this works: http://127.0.0.1:5001/activity?where=status==Ok

Name: Eve Version: 0.6.4

Name: SQLAlchemy Version: 1.1.4

Name: Eve-SQLAlchemy Version: 0.4.1

''' --> Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/eve/flaskapp.py", line 968, in call return super(Eve, self).call(environ, start_response) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1836, in call return self.wsgi_app(environ, start_response) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python2.6/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python2.6/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python2.6/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functionsrule.endpoint File "/usr/lib/python2.6/site-packages/eve/endpoints.py", line 54, in collections_endpoint response = get(resource, lookup) File "/usr/lib/python2.6/site-packages/eve/methods/common.py", line 242, in rate_limited return f(*args, *kwargs) File "/usr/lib/python2.6/site-packages/eve/auth.py", line 79, in decorated return f(args, kwargs) File "/usr/lib/python2.6/site-packages/eve/methods/common.py", line 949, in decorated r = f(resource, combined_args) File "/usr/lib/python2.6/site-packages/eve/methods/get.py", line 101, in get cursor = app.data.find(resource, req, lookup) File "/usr/lib/python2.6/site-packages/eve_sqlalchemy/init.py", line 123, in find spec = json.loads(req.where) File "/usr/lib64/python2.6/site-packages/simplejson/init.py", line 516, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/site-packages/simplejson/decoder.py", line 374, in decode obj, end = self.raw_decode(s) File "/usr/lib64/python2.6/site-packages/simplejson/decoder.py", line 404, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) JSONDecodeError: Expecting value: line 1 column 1 (char 0) '''

dkellner commented 7 years ago

Thank you for reporting this issue. We're preparing a new release at the moment. It should work using the current master branch - can you verify this?

dkellner commented 7 years ago

I just tried this myself with the trivial example: curl -i http://localhost:5000/people?where={"lastname":"Jefferson"} will throw the same exception, but this is due to wrong escaping on the client side (curl). You should turn of the "URL globbing parser" when you use {} in URLs: curl -ig http://localhost:5000/people?where={"lastname":"Jefferson"}. With -g, it works with both query expressions.


We still have an issue here, though. Even a faulty user query should not result in an uncaught exception and HTTP 500, but HTTP 400 (Bad request).

Suggested steps:

  1. See what Eve is doing when getting a request like this. If they same issue exists there, we should fix it there (or at least file an issue).
  2. Write a test. Even if it's currently a non-issue in Eve, it might still be worth considering adding the test there.
  3. Fix it :).