Allow values that are not dictionaries in the request params in the /search endpoint (#2720)

* let params contain something else than dictionaries

* rewrite the test same style as the main branch
This commit is contained in:
Massimiliano Pippi 2022-07-15 13:24:29 +02:00 committed by GitHub
parent 6b39fbd39c
commit 632cd1c141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from typing import Dict, Any
import collections
import logging
import time
import json
@ -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)

View File

@ -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