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

Empty filter causes server error #17

Closed
louise-davies opened this issue Jun 28, 2019 · 2 comments · Fixed by #20
Closed

Empty filter causes server error #17

louise-davies opened this issue Jun 28, 2019 · 2 comments · Fixed by #20
Labels
bug Something isn't working

Comments

@louise-davies
Copy link
Member

Sending a request with the filter set to empty object (filter={}) causes the server to error and return a 500 error. Although best practice in the front end should be to not set this property if filters aren't applied - it probably shouldn't break the API either.

Traceback (most recent call last):
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask_restful\__init__.py", line 269, in error_router
    return original_handler(e)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\_compat.py", line 34, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask_restful\__init__.py", line 269, in error_router
    return original_handler(e)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\_compat.py", line 34, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask_restful\__init__.py", line 458, in wrapper
    resp = resource(*args, **kwargs)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask\views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "C:\Users\mnf98541\anaconda3\lib\site-packages\flask_restful\__init__.py", line 573, in dispatch_request
    resp = meth(*args, **kwargs)
  File "C:\code\datagateway-api\common\helpers.py", line 34, in wrapper_requires_session
    return method(*args, **kwargs)
  File "C:\code\datagateway-api\common\helpers.py", line 54, in wrapper_gets_records
    return method(*args, **kwargs)
  File "C:\code\datagateway-api\src\resources\entities\investigations_endpoints.py", line 14, in get
    return get_rows_by_filter(INVESTIGATION, get_filters_from_query_string()), 200
  File "C:\code\datagateway-api\common\database_helpers.py", line 127, in get_rows_by_filter
    if list(filter)[0].lower() == "where":
IndexError: list index out of range
@louise-davies louise-davies added the bug Something isn't working label Jun 28, 2019
@keiranjprice101
Copy link
Collaborator

@louise-davies What would be the best response in this event, 400 or just an unfiltered get all?

keiranjprice101 added a commit that referenced this issue Jun 28, 2019
@louise-davies
Copy link
Member Author

@keiranjprice101 In my opinion unfiltered get all - an empty set of filters is valid in the sense that we're asking for data with explicitly no filters applied. Essentially, ?filter={} should be ignored and treated the same not having a filter param at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants