diff --git a/rest_api/controller/search.py b/rest_api/controller/search.py index 9bf8c9f21f..f8a716baec 100644 --- a/rest_api/controller/search.py +++ b/rest_api/controller/search.py @@ -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) diff --git a/rest_api/test/test_rest_api.py b/rest_api/test/test_rest_api.py index d849114305..6d9a7fcb29 100644 --- a/rest_api/test/test_rest_api.py +++ b/rest_api/test/test_rest_api.py @@ -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