Skip to content

Commit 7fd5dbe

Browse files
committed
feat: Adding support for index renaming.
1 parent fb58d6d commit 7fd5dbe

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

meilisearch/index.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def update(self, primary_key: Optional[str] = None, new_uid: Optional[str] = Non
125125
MeilisearchApiError
126126
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
127127
"""
128+
if primary_key is None and new_uid is None:
129+
raise ValueError("You must provide either 'primary_key' or 'new_uid' to update the index.")
130+
128131
payload = {}
129132
if primary_key is not None:
130133
payload["primaryKey"] = primary_key

tests/index/test_index.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,13 @@ def test_index_update_and_rename(client):
273273
info = renamed_index.fetch_info()
274274
assert info.uid == new_uid
275275
assert renamed_index.get_primary_key() == "objectID"
276+
277+
278+
@pytest.mark.usefixtures("indexes_sample")
279+
def test_index_update_without_params(client):
280+
"""Test updating primary key and renaming an index together."""
281+
index = client.index(common.INDEX_UID)
282+
with pytest.raises(ValueError) as exc:
283+
index.update()
284+
285+
assert "primary_key" in str(exc.value) or "new_uid" in str(exc.value)

0 commit comments

Comments
 (0)