Skip to content

Commit 74dd9eb

Browse files
author
diana
committed
fix: Address CodeRabbit review feedback on dynamic search rules
- index.py: Fix upsert_dynamic_search_rule path to use top-level route /dynamic-search-rules/{uid} instead of index-scoped path - .code-samples.meilisearch.yaml: Fix patch sample to use camelCase keys (documentIds, matchCondition) and correct conditions array structure with scope/operator/value fields per v1.41 API spec - tests: Replace tautological assertion in test_list with meaningful checks (isinstance dict, results/meta key, results is list) - tests: Replace try/except with pytest.raises(MeilisearchApiError) in test_delete verification; add MeilisearchApiError import
1 parent 1b56432 commit 74dd9eb

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

.code-samples.meilisearch.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,20 @@ get_dynamic_search_rule_1: |-
631631
632632
patch_dynamic_search_rule_1: |-
633633
client.index('movies').upsert_dynamic_search_rule('promote-new', {
634-
'condition': "query = 'new'",
635-
'match_condition': 'all',
634+
'conditions': [
635+
{
636+
'scope': ['title'],
637+
'operator': 'contains',
638+
'value': 'new'
639+
}
640+
],
636641
'actions': [
637642
{
638643
'action': 'promote',
639-
'document_ids': ['1', '2'],
640-
'position': 1
644+
'documentIds': ['1', '2'],
645+
'matchCondition': 'all'
641646
}
642647
]
643648
})
644-
645649
delete_dynamic_search_rule_1: |-
646650
client.index('movies').delete_dynamic_search_rule('promote-new')

meilisearch/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ def upsert_dynamic_search_rule(self, uid: str, body: Dict[str, Any]) -> TaskInfo
13841384
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
13851385
"""
13861386
task = self.http.patch(
1387-
f"{self.config.paths.index}/{self.uid}/{self.config.paths.dynamic_search_rules}/{uid}",
1387+
f"{self.config.paths.dynamic_search_rules}/{uid}",
13881388
body,
13891389
)
13901390

tests/index/test_index_dynamic_search_rules_meilisearch.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from meilisearch.errors import MeilisearchApiError
23

34

45
@pytest.fixture
@@ -12,7 +13,9 @@ def test_list_dynamic_search_rules(test_index):
1213
"""Test listing dynamic search rules"""
1314
response = test_index.list_dynamic_search_rules()
1415
assert isinstance(response, dict)
15-
assert "results" in response or "results" not in response # May be empty
16+
assert "results" in response or "meta" in response
17+
if "results" in response:
18+
assert isinstance(response["results"], list)
1619

1720

1821
def test_get_dynamic_search_rule(test_index):
@@ -91,9 +94,5 @@ def test_delete_dynamic_search_rule(test_index):
9194
test_index.wait_for_task(delete_response.task_uid)
9295

9396
# Verify it's deleted - should raise error or return empty
94-
try:
97+
with pytest.raises(MeilisearchApiError):
9598
test_index.get_dynamic_search_rule(rule_uid)
96-
assert False, "Rule should have been deleted"
97-
except Exception:
98-
# Expected - rule doesn't exist
99-
pass

0 commit comments

Comments
 (0)