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

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

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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