Skip to content

Commit 1246a36

Browse files
bors[bot]adripoalallema
authored
Merge #586
586: Fix add_document behaviour with empty string r=alallema a=adripo # Pull Request ## Related issue Fixes #585 ## What does this PR do? - Receive a formal message for this case from Meilisearch API. - Test correct functionality ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: adripo <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents ffa63f0 + a30da3b commit 1246a36

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

meilisearch/_httprequests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def send_request(
4545
request_path,
4646
timeout=self.config.timeout,
4747
headers=self.headers,
48-
data=json.dumps(body) if body else "null",
48+
data=json.dumps(body) if body else "" if body == "" else "null",
4949
)
5050
return self.__validate(request)
5151

tests/index/test_index_document_meilisearch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def test_add_documents(empty_index, small_movies):
2626
assert update.status == "succeeded"
2727

2828

29+
def test_add_documents_empty(empty_index):
30+
"""Tests adding empty string as documents to a clean index."""
31+
index = empty_index()
32+
with pytest.raises(Exception) as e_info:
33+
index.add_documents("")
34+
assert e_info.value.code == "missing_payload"
35+
assert e_info.value.type == "invalid_request"
36+
assert e_info.value.link == "https://docs.meilisearch.com/errors#missing_payload"
37+
38+
2939
@pytest.mark.parametrize("batch_size", [2, 3, 1000])
3040
@pytest.mark.parametrize(
3141
"primary_key, expected_primary_key",

0 commit comments

Comments
 (0)