From 06ee23ecb1e435ebe4c5964db6caeaed6edc4527 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:23:34 -0400 Subject: [PATCH 1/4] new: cover edge case in import_bulk test --- tests/test_document.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_document.py b/tests/test_document.py index 02c47bc4..2bada588 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -1842,6 +1842,10 @@ def test_document_import_bulk(col, bad_col, docs): assert type(result) is list 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] From 0fc0de6f60d89c8db682f5eadaef445ec2021c5c Mon Sep 17 00:00:00 2001 From: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:25:01 -0400 Subject: [PATCH 2/4] fix: cover import_bulk edge case --- arango/collection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arango/collection.py b/arango/collection.py index 3aea6f81..7e949ee2 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -1992,12 +1992,16 @@ 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. Should not be used + if **overwrite** is set to true. :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: + raise ValueError("Cannot set **batch_size** if **overwrite** is true") + documents = [self._ensure_key_from_id(doc) for doc in documents] params: Params = {"type": "array", "collection": self.name} From 7eaa046b54c8304bddfd7d5e080e64f3a07514ee Mon Sep 17 00:00:00 2001 From: aMahanna Date: Mon, 27 Jun 2022 22:25:42 -0400 Subject: [PATCH 3/4] fix: black --- tests/test_document.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_document.py b/tests/test_document.py index 2bada588..d7db480a 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -1842,7 +1842,7 @@ def test_document_import_bulk(col, bad_col, docs): assert type(result) is list 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) From 06b76ee77c53143598c5498a671f48682ecce6d5 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> Date: Tue, 28 Jun 2022 18:22:24 -0400 Subject: [PATCH 4/4] fix: address comments --- arango/collection.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arango/collection.py b/arango/collection.py index 7e949ee2..aac97bb9 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -1992,15 +1992,16 @@ 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. Should not be used - if **overwrite** is set to true. + 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: - raise ValueError("Cannot set **batch_size** if **overwrite** is true") + 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]