Skip to content

Commit f5b1d50

Browse files
authored
new: raise_on_document_error param for collection.update_many (#273)
1 parent 10f6ece commit f5b1d50

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

arango/collection.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ def update_many(
15901590
sync: Optional[bool] = None,
15911591
silent: bool = False,
15921592
refill_index_caches: Optional[bool] = None,
1593+
raise_on_document_error: bool = False,
15931594
) -> Result[Union[bool, List[Union[Json, ArangoServerError]]]]:
15941595
"""Update multiple documents.
15951596
@@ -1599,7 +1600,8 @@ def update_many(
15991600
returned as an object in the result list. It is up to you to
16001601
inspect the list to determine which documents were updated
16011602
successfully (returns document metadata) and which were not
1602-
(returns exception object).
1603+
(returns exception object). Alternatively, you can rely on
1604+
setting **raise_on_document_error** to True (defaults to False).
16031605
16041606
.. note::
16051607
@@ -1636,6 +1638,11 @@ def update_many(
16361638
index caches if document operations affect the edge index or
16371639
cache-enabled persistent indexes.
16381640
:type refill_index_caches: bool | None
1641+
:param raise_on_document_error: Whether to raise if a DocumentRevisionError
1642+
or a DocumentUpdateError is encountered on an individual document,
1643+
as opposed to returning the error as an object in the result list.
1644+
Defaults to False.
1645+
:type raise_on_document_error: bool
16391646
:return: List of document metadata (e.g. document keys, revisions) and
16401647
any exceptions, or True if parameter **silent** was set to True.
16411648
:rtype: [dict | ArangoError] | bool
@@ -1689,6 +1696,9 @@ def response_handler(
16891696
else: # pragma: no cover
16901697
error = DocumentUpdateError(sub_resp, request)
16911698

1699+
if raise_on_document_error:
1700+
raise error
1701+
16921702
results.append(error)
16931703

16941704
return results

tests/test_document.py

+11
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ def test_document_update_many(col, bad_col, docs):
631631
bad_col.update_many([{}])
632632
assert str(err.value) == 'field "_key" or "_id" required'
633633

634+
# Test update_many with raise on document error (revision)
635+
with assert_raises(DocumentRevisionError) as err:
636+
# Raises: [HTTP 202][ERR 1200] conflict, _rev values do not match
637+
col.update_many(docs, raise_on_document_error=True)
638+
639+
# Test update_many with raise on document error (update)
640+
with assert_raises(DocumentUpdateError) as err:
641+
# Raises: [HTTP 202][ERR 1202] document not found
642+
bad_docs = [{"_key": "unknown_doc", "foo": "bar"}]
643+
col.update_many(bad_docs, raise_on_document_error=True)
644+
634645

635646
def test_document_update_match(col, bad_col, docs):
636647
# Set up test documents

0 commit comments

Comments
 (0)