Skip to content

Commit 1507ed5

Browse files
committed
index: delete_document routes return
1 parent 9034e22 commit 1507ed5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

meilisearch/index.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def delete_document(self, document_id: str) -> TaskInfo:
593593
)
594594
return TaskInfo(**response)
595595

596-
def delete_documents(self, ids: List[str]) -> Dict[str, int]:
596+
def delete_documents(self, ids: List[str]) -> TaskInfo:
597597
"""Delete multiple documents from the index.
598598
599599
Parameters
@@ -603,37 +603,39 @@ def delete_documents(self, ids: List[str]) -> Dict[str, int]:
603603
604604
Returns
605605
-------
606-
task:
607-
Dictionary containing a task to track the informations about the progress of an asynchronous process.
606+
TaskInfo:
607+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
608608
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
609609
610610
Raises
611611
------
612612
MeiliSearchApiError
613613
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
614614
"""
615-
return self.http.post(
615+
response = self.http.post(
616616
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete-batch',
617617
ids
618618
)
619+
return TaskInfo(**response)
619620

620-
def delete_all_documents(self) -> Dict[str, int]:
621+
def delete_all_documents(self) -> TaskInfo:
621622
"""Delete all documents from the index.
622623
623624
Returns
624625
-------
625-
task:
626-
Dictionary containing a task to track the informations about the progress of an asynchronous process.
626+
TaskInfo:
627+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
627628
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
628629
629630
Raises
630631
------
631632
MeiliSearchApiError
632633
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
633634
"""
634-
return self.http.delete(
635+
response = self.http.delete(
635636
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}'
636637
)
638+
return TaskInfo(**response)
637639

638640
# GENERAL SETTINGS ROUTES
639641

tests/index/test_index_document_meilisearch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def test_delete_documents(index_with_documents):
140140
to_delete = ['522681', '450465', '329996']
141141
index = index_with_documents()
142142
response = index.delete_documents(to_delete)
143-
assert isinstance(response, dict)
144-
assert 'taskUid' in response
145-
index.wait_for_task(response['taskUid'])
143+
assert isinstance(response, TaskInfo)
144+
assert response.task_uid != None
145+
index.wait_for_task(response.task_uid)
146146
for document in to_delete:
147147
with pytest.raises(Exception):
148148
index.get_document(document)
@@ -151,9 +151,9 @@ def test_delete_all_documents(index_with_documents):
151151
"""Tests deleting all the documents in the index."""
152152
index = index_with_documents()
153153
response = index.delete_all_documents()
154-
assert isinstance(response, dict)
155-
assert 'taskUid' in response
156-
index.wait_for_task(response['taskUid'])
154+
assert isinstance(response, TaskInfo)
155+
assert response.task_uid != None
156+
index.wait_for_task(response.task_uid)
157157
response = index.get_documents()
158158
assert isinstance(response.results, list)
159159
assert response.results == []

0 commit comments

Comments
 (0)