Skip to content

Commit

Permalink
Allow values that are not dictionaries in the request params in the `…
Browse files Browse the repository at this point in the history
…/search` endpoint (#2720)

* let params contain something else than dictionaries

* rewrite the test same style as the main branch
  • Loading branch information
masci authored Jul 15, 2022
1 parent 6b39fbd commit 632cd1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rest_api/controller/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict, Any

import collections
import logging
import time
import json
Expand Down Expand Up @@ -72,7 +73,7 @@ def _process_request(pipeline, request) -> Dict[str, Any]:

# format targeted node filters (e.g. "params": {"Retriever": {"filters": {"value"}}})
for key in params.keys():
if "filters" in params[key].keys():
if isinstance(params[key], collections.Mapping) and "filters" in params[key].keys():
params[key]["filters"] = _format_filters(params[key]["filters"])

result = pipeline.run(query=request.query, params=params, debug=request.debug)
Expand Down
19 changes: 19 additions & 0 deletions rest_api/test/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,25 @@ def test_query_with_no_documents_and_no_answers(client):
assert response_json["answers"] == []


def test_query_with_bool_in_params(client):
"""
Ensure items of params can be other types than dictionary, see
https://github.com/deepset-ai/haystack/issues/2656
"""
with mock.patch("rest_api.controller.search.query_pipeline") as mocked_pipeline:
# `run` must return a dictionary containing a `query` key
mocked_pipeline.run.return_value = {"query": TEST_QUERY}
request_body = {
"query": TEST_QUERY,
"params": {"debug": True, "Retriever": {"top_k": 5}, "Reader": {"top_k": 3}},
}
response = client.post(url="/query", json=request_body)
assert 200 == response.status_code
response_json = response.json()
assert response_json["documents"] == []
assert response_json["answers"] == []


def test_write_feedback(client, feedback):
response = client.post(url="/feedback", json=feedback)
assert 200 == response.status_code
Expand Down

0 comments on commit 632cd1c

Please sign in to comment.