Skip to content

Commit 6d0ea1e

Browse files
committed
Don't send body if empty
1 parent f788922 commit 6d0ea1e

7 files changed

+14
-9
lines changed

meilisearch/_httprequests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ def send_request(
3333
self.headers["Content-Type"] = content_type
3434
try:
3535
request_path = self.config.url + "/" + path
36-
if isinstance(body, bytes):
36+
if body is None or body == "":
37+
request = http_method(
38+
request_path,
39+
timeout=self.config.timeout,
40+
headers=self.headers,
41+
)
42+
elif isinstance(body, bytes):
3743
request = http_method(
3844
request_path,
3945
timeout=self.config.timeout,
@@ -45,7 +51,7 @@ def send_request(
4551
request_path,
4652
timeout=self.config.timeout,
4753
headers=self.headers,
48-
data=json.dumps(body) if body else "" if body == "" else "null",
54+
data=json.dumps(body),
4955
)
5056
return self.__validate(request)
5157

tests/settings/test_settings_displayed_attributes_meilisearch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def test_update_displayed_attributes_to_none(empty_index):
3636
get_attributes = index.get_displayed_attributes()
3737
for attribute in DISPLAYED_ATTRIBUTES:
3838
assert attribute in get_attributes
39-
# Launch test to update at null the setting
40-
response = index.update_displayed_attributes(None)
39+
response = index.reset_displayed_attributes()
4140
index.wait_for_task(response.task_uid)
4241
response = index.get_displayed_attributes()
4342
assert response == ["*"]

tests/settings/test_settings_distinct_attribute_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_update_distinct_at_to_none(empty_index):
2828
response = index.get_distinct_attribute()
2929
assert response == NEW_DISTINCT_ATTRIBUTE
3030
# Launch test to update at null the setting
31-
response = index.update_distinct_attribute(None)
31+
response = index.reset_distinct_attribute()
3232
index.wait_for_task(response.task_uid)
3333
response = index.get_distinct_attribute()
3434
assert response == DEFAULT_DISTINCT_ATTRIBUTE

tests/settings/test_settings_filterable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_update_filterable_attributes_to_none(empty_index):
3232
for attribute in FILTERABLE_ATTRIBUTES:
3333
assert attribute in get_attributes
3434
# Launch test to update at null the setting
35-
response = index.update_filterable_attributes(None)
35+
response = index.reset_filterable_attributes()
3636
index.wait_for_task(response.task_uid)
3737
response = index.get_filterable_attributes()
3838
assert response == []

tests/settings/test_settings_ranking_rules_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_update_ranking_rules_none(empty_index):
3131
for rule in NEW_RANKING_RULES:
3232
assert rule in response
3333
# Launch test to update at null the setting
34-
response = index.update_ranking_rules(None)
34+
response = index.reset_ranking_rules()
3535
index.wait_for_task(response.task_uid)
3636
response = index.get_ranking_rules()
3737
for rule in DEFAULT_RANKING_RULES:

tests/settings/test_settings_searchable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_update_searchable_attributes_to_none(empty_index):
3737
for attribute in NEW_SEARCHABLE_ATTRIBUTES:
3838
assert attribute in response
3939
# Launch test to update at null the setting
40-
response = index.update_searchable_attributes(None)
40+
response = index.reset_searchable_attributes()
4141
index.wait_for_task(response.task_uid)
4242
response = index.get_searchable_attributes()
4343
assert response == ["*"]

tests/settings/test_settings_sortable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_update_sortable_attributes_to_none(empty_index):
3232
for attribute in SORTABLE_ATTRIBUTES:
3333
assert attribute in get_attributes
3434
# Launch test to update at null the setting
35-
response = index.update_sortable_attributes(None)
35+
response = index.reset_sortable_attributes()
3636
index.wait_for_task(response.task_uid)
3737
response = index.get_sortable_attributes()
3838
assert response == []

0 commit comments

Comments
 (0)