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

Pass back query errors as 400s #10

Open
jrdh opened this issue Jul 2, 2019 · 0 comments
Open

Pass back query errors as 400s #10

jrdh opened this issue Jul 2, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@jrdh
Copy link
Member

jrdh commented Jul 2, 2019

When a user makes a query using the elasticsearch raw endpoint they can send crap queries and they should have a useful error return if they do a duff one. For example:

{
  "query": {
    "exists": "weight"
  }
}

produces this error in the logs:

[Tue Jul 02 17:06:48.025699 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/src/ckanext-versioned-datastore/ckanext/versioned_datastore/logic/action.py", line 643, in datastore_search_raw
[Tue Jul 02 17:06:48.025717 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     search = Search.from_dict(search)
[Tue Jul 02 17:06:48.025725 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/search.py", line 375, in from_dict
[Tue Jul 02 17:06:48.025755 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     s.update_from_dict(d)
[Tue Jul 02 17:06:48.025763 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/search.py", line 417, in update_from_dict
[Tue Jul 02 17:06:48.025774 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     self.query._proxied = Q(d.pop('query'))
[Tue Jul 02 17:06:48.025784 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/query.py", line 18, in Q
[Tue Jul 02 17:06:48.025793 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     return Query.get_dsl_class(name)(_expand__to_dot=False, **params)
[Tue Jul 02 17:06:48.025798 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 224, in __init__
[Tue Jul 02 17:06:48.025807 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     self._setattr(pname, pvalue)
[Tue Jul 02 17:06:48.025813 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 263, in _setattr
[Tue Jul 02 17:06:48.025820 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     value = list(map(shortcut, value))
[Tue Jul 02 17:06:48.025826 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]   File "/usr/lib/ckan/default/lib/python2.7/site-packages/elasticsearch_dsl/query.py", line 18, in Q
[Tue Jul 02 17:06:48.025833 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938]     return Query.get_dsl_class(name)(_expand__to_dot=False, **params)
[Tue Jul 02 17:06:48.025849 2019] [:error] [pid 45102:tid 140182646204160] [remote 157.140.2.190:20938] TypeError: DslMeta object argument after ** must be a mapping, not unicode

and therefore the user gets a 500 error when they should get a 400 error (the exists query uses a "field" key).

@jrdh jrdh added the enhancement New feature or request label Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant