Skip to content

Commit

Permalink
Prevent batch_size usage when overwrite is set to True in bulk_import
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna authored Jun 28, 2022
1 parent 917f699 commit 76ca077
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,12 +1992,17 @@ def import_bulk(
IMPORTANT NOTE: this parameter may go through breaking changes
in the future where the return type may not be a list of result
objects anymore. Use it at your own risk, and avoid
depending on the return value if possible.
depending on the return value if possible. Cannot be used with
parameter **overwrite**.
:type batch_size: int
:return: Result of the bulk import.
:rtype: dict | list[dict]
:raise arango.exceptions.DocumentInsertError: If import fails.
"""
if overwrite and batch_size is not None:
msg = "Cannot use parameter 'batch_size' if 'overwrite' is set to True"
raise ValueError(msg)

documents = [self._ensure_key_from_id(doc) for doc in documents]

params: Params = {"type": "array", "collection": self.name}
Expand Down
4 changes: 4 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,10 @@ def test_document_import_bulk(col, bad_col, docs):
assert len(result) == 1
empty_collection(col)

# Test import bulk with overwrite and batch_size
with pytest.raises(ValueError):
col.import_bulk(docs, overwrite=True, batch_size=1)

# Test import bulk on_duplicate actions
doc = docs[0]
doc_key = doc["_key"]
Expand Down

0 comments on commit 76ca077

Please sign in to comment.