Skip to content

Made arg document_id to take both types str or int #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def search(self, query: str, opt_params: dict[str, Any] | None = None) -> dict[s
body=body
)

def get_document(self, document_id: str, parameters: dict[str, Any] | None = None) -> Document:
def get_document(self, document_id: str | int, parameters: dict[str, Any] | None = None) -> Document:
"""Get one document with given document identifier.

Parameters
Expand Down Expand Up @@ -573,7 +573,7 @@ def update_documents_in_batches(

return tasks

def delete_document(self, document_id: str) -> TaskInfo:
def delete_document(self, document_id: str | int) -> TaskInfo:
"""Delete one document from the index.

Parameters
Expand All @@ -597,7 +597,7 @@ def delete_document(self, document_id: str) -> TaskInfo:
)
return TaskInfo(**response)

def delete_documents(self, ids: list[str]) -> TaskInfo:
def delete_documents(self, ids: list[str | int]) -> TaskInfo:
"""Delete multiple documents from the index.

Parameters
Expand All @@ -618,7 +618,7 @@ def delete_documents(self, ids: list[str]) -> TaskInfo:
"""
response = self.http.post(
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete-batch',
ids
[str(i) for i in ids]
)
return TaskInfo(**response)

Expand Down
2 changes: 1 addition & 1 deletion tests/index/test_index_document_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_delete_document(index_with_documents):

def test_delete_documents(index_with_documents):
"""Tests deleting a set of documents."""
to_delete = ['522681', '450465', '329996']
to_delete = [522681, '450465', 329996]
index = index_with_documents()
response = index.delete_documents(to_delete)
assert isinstance(response, TaskInfo)
Expand Down