@@ -1752,6 +1752,7 @@ def insert_many(
1752
1752
merge : Optional [bool ] = None ,
1753
1753
refill_index_caches : Optional [bool ] = None ,
1754
1754
version_attribute : Optional [str ] = None ,
1755
+ raise_on_document_error : bool = False ,
1755
1756
) -> Result [Union [bool , List [Union [Json , ArangoServerError ]]]]:
1756
1757
"""Insert multiple documents.
1757
1758
@@ -1761,7 +1762,8 @@ def insert_many(
1761
1762
returned as an object in the result list. It is up to you to
1762
1763
inspect the list to determine which documents were inserted
1763
1764
successfully (returns document metadata) and which were not
1764
- (returns exception object).
1765
+ (returns exception object). Alternatively, you can rely on
1766
+ setting **raise_on_document_error** to True (defaults to False).
1765
1767
1766
1768
:param documents: List of new documents to insert. If they contain the
1767
1769
"_key" or "_id" fields, the values are used as the keys of the new
@@ -1801,6 +1803,11 @@ def insert_many(
1801
1803
:param version_attribute: support for simple external versioning to
1802
1804
document operations.
1803
1805
:type version_attribute: str
1806
+ :param raise_on_document_error: Whether to raise if a DocumentRevisionError
1807
+ or a DocumentInsertError is encountered on an individual document,
1808
+ as opposed to returning the error as an object in the result list.
1809
+ Defaults to False.
1810
+ :type raise_on_document_error: bool
1804
1811
:return: List of document metadata (e.g. document keys, revisions) and
1805
1812
any exception, or True if parameter **silent** was set to True.
1806
1813
:rtype: [dict | ArangoServerError] | bool
@@ -1853,7 +1860,12 @@ def response_handler(
1853
1860
results .append (body )
1854
1861
else :
1855
1862
sub_resp = self ._conn .prep_bulk_err_response (resp , body )
1856
- results .append (DocumentInsertError (sub_resp , request ))
1863
+ error = DocumentInsertError (sub_resp , request )
1864
+
1865
+ if raise_on_document_error :
1866
+ raise error
1867
+
1868
+ results .append (error )
1857
1869
1858
1870
return results
1859
1871
@@ -2228,6 +2240,7 @@ def delete_many(
2228
2240
sync : Optional [bool ] = None ,
2229
2241
silent : bool = False ,
2230
2242
refill_index_caches : Optional [bool ] = None ,
2243
+ raise_on_document_error : bool = False ,
2231
2244
) -> Result [Union [bool , List [Union [Json , ArangoServerError ]]]]:
2232
2245
"""Delete multiple documents.
2233
2246
@@ -2256,6 +2269,11 @@ def delete_many(
2256
2269
index caches if document operations affect the edge index or
2257
2270
cache-enabled persistent indexes.
2258
2271
:type refill_index_caches: bool | None
2272
+ :param raise_on_document_error: Whether to raise if a DocumentRevisionError
2273
+ or a DocumentDeleteError is encountered on an individual document,
2274
+ as opposed to returning the error as an object in the result list.
2275
+ Defaults to False.
2276
+ :type raise_on_document_error: bool
2259
2277
:return: List of document metadata (e.g. document keys, revisions) and
2260
2278
any exceptions, or True if parameter **silent** was set to True.
2261
2279
:rtype: [dict | ArangoServerError] | bool
@@ -2307,6 +2325,10 @@ def response_handler(
2307
2325
error = DocumentRevisionError (sub_resp , request )
2308
2326
else :
2309
2327
error = DocumentDeleteError (sub_resp , request )
2328
+
2329
+ if raise_on_document_error :
2330
+ raise error
2331
+
2310
2332
results .append (error )
2311
2333
2312
2334
return results
0 commit comments