Skip to content
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

Bug fix for document_store.py #618

Merged
merged 4 commits into from
Apr 24, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,15 @@ def _convert_input_document(document: Union[dict, Document]):
documents_to_write = [_convert_input_document(doc) for doc in documents]

duplicate_documents = []
new_documents = []
new_documents: List[Document] = []
i = 0
while i < len(documents_to_write):
doc = documents_to_write[i]
# check to see if this ID already exists in our new_documents array
exists = [d for d in new_documents if d["_id"] == doc["_id"]]
# check to see if this ID is already in the DB
response = self.index.find_documents({"filter": {"_id": doc["_id"]}})
if response:
if response or exists:
if policy == DuplicatePolicy.FAIL:
msg = f"ID '{doc['_id']}' already exists."
raise DuplicateDocumentError(msg)
Expand Down
7 changes: 7 additions & 0 deletions integrations/astra/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def test_write_documents(self, document_store: AstraDocumentStore):
assert document_store.write_documents(documents=[doc1], policy=DuplicatePolicy.OVERWRITE) == 1
self.assert_documents_are_equal(document_store.filter_documents(), [doc1])

def test_write_documents_skip_duplicates(self, document_store: AstraDocumentStore):
docs = [
Document(id="1", content="test doc 1"),
Document(id="1", content="test doc 2"),
]
assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 1

def test_delete_documents_non_existing_document(self, document_store: AstraDocumentStore):
"""
Test delete_documents() doesn't delete any Document when called with non existing id.
Expand Down