Skip to content

Commit 3c22c85

Browse files
committed
feat: Adds an optional skipCreation. When set to true, documents that don't exist in the index are silently ignored rather than created.
1 parent 80001ac commit 3c22c85

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

tests/index/test_index_document_meilisearch.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pytest
1111

12+
from meilisearch.errors import MeilisearchApiError
1213
from meilisearch.models.document import Document
1314
from meilisearch.models.task import TaskInfo
1415

@@ -207,7 +208,7 @@ def test_get_document_with_fields(index_with_documents):
207208

208209
def test_get_document_inexistent(empty_index):
209210
"""Tests getting one inexistent document from a populated index."""
210-
with pytest.raises(Exception):
211+
with pytest.raises(MeilisearchApiError):
211212
empty_index().get_document("123")
212213

213214

@@ -419,7 +420,7 @@ def test_delete_document(index_with_documents):
419420
assert isinstance(response, TaskInfo)
420421
assert response.task_uid is not None
421422
index.wait_for_task(response.task_uid)
422-
with pytest.raises(Exception):
423+
with pytest.raises(MeilisearchApiError):
423424
index.get_document("500682")
424425

425426

@@ -433,7 +434,7 @@ def test_delete_documents_by_id(index_with_documents):
433434
assert response.task_uid is not None
434435
index.wait_for_task(response.task_uid)
435436
for document in to_delete:
436-
with pytest.raises(Exception):
437+
with pytest.raises(MeilisearchApiError):
437438
index.get_document(document)
438439
assert "The use of ids is depreciated" in str(w[0].message)
439440

@@ -581,8 +582,8 @@ def test_add_documents_with_skip_creation_true(empty_index):
581582
task = index.add_documents(new_documents, skip_creation=True)
582583
index.wait_for_task(task.task_uid)
583584

584-
# New document should not exist
585-
with pytest.raises(Exception):
585+
# Document "2" should not exist because skip_creation=True prevents creation of new documents
586+
with pytest.raises(MeilisearchApiError):
586587
index.get_document("2")
587588

588589
# Existing document should still be there
@@ -647,8 +648,8 @@ def test_update_documents_with_skip_creation_true(empty_index):
647648
task = index.update_documents(new_documents, skip_creation=True)
648649
index.wait_for_task(task.task_uid)
649650

650-
# New document should not exist
651-
with pytest.raises(Exception):
651+
# Document "2" should not exist because skip_creation=True prevents creation of new documents
652+
with pytest.raises(MeilisearchApiError):
652653
index.get_document("2")
653654

654655
# Existing document should still be there and unchanged

0 commit comments

Comments
 (0)