@@ -376,10 +376,10 @@ def response_handler(resp):
376
376
raise CollectionStatisticsError (resp , request )
377
377
378
378
stats = resp .body .get ('figures' , resp .body )
379
- for field in ['compactors' , 'datafiles' , 'journals' ]:
380
- if field in stats and 'fileSize' in stats [field ]:
381
- stats [field ]['file_size' ] = stats [field ].pop ('fileSize' )
382
- if 'compactionStatus' in stats :
379
+ for f in ['compactors' , 'datafiles' , 'journals' ]:
380
+ if f in stats and 'fileSize' in stats [f ]: # pragma: no cover
381
+ stats [f ]['file_size' ] = stats [f ].pop ('fileSize' )
382
+ if 'compactionStatus' in stats : # pragma: no cover
383
383
status = stats .pop ('compactionStatus' )
384
384
if 'bytesRead' in status :
385
385
status ['bytes_read' ] = status .pop ('bytesRead' )
@@ -388,15 +388,15 @@ def response_handler(resp):
388
388
if 'filesCombined' in status :
389
389
status ['files_combined' ] = status .pop ('filesCombined' )
390
390
stats ['compaction_status' ] = status
391
- if 'documentReferences' in stats :
391
+ if 'documentReferences' in stats : # pragma: no cover
392
392
stats ['document_refs' ] = stats .pop ('documentReferences' )
393
- if 'lastTick' in stats :
393
+ if 'lastTick' in stats : # pragma: no cover
394
394
stats ['last_tick' ] = stats .pop ('lastTick' )
395
- if 'waitingFor' in stats :
395
+ if 'waitingFor' in stats : # pragma: no cover
396
396
stats ['waiting_for' ] = stats .pop ('waitingFor' )
397
397
if 'documentsSize' in stats : # pragma: no cover
398
398
stats ['documents_size' ] = stats .pop ('documentsSize' )
399
- if 'uncollectedLogfileEntries' in stats :
399
+ if 'uncollectedLogfileEntries' in stats : # pragma: no cover
400
400
stats ['uncollected_logfile_entries' ] = \
401
401
stats .pop ('uncollectedLogfileEntries' )
402
402
return stats
@@ -793,7 +793,7 @@ def response_handler(resp):
793
793
794
794
return self ._execute (request , response_handler )
795
795
796
- def find_near (self , latitude , longitude , limit = None ):
796
+ def find_near (self , latitude , longitude , limit = None ): # pragma: no cover
797
797
"""Return documents near a given coordinate.
798
798
799
799
Documents returned are sorted according to distance, with the nearest
@@ -1219,7 +1219,7 @@ def response_handler(resp):
1219
1219
index ['min_length' ] = index .pop ('minLength' )
1220
1220
if 'geoJson' in index :
1221
1221
index ['geo_json' ] = index .pop ('geoJson' )
1222
- if 'ignoreNull' in index :
1222
+ if 'ignoreNull' in index : # pragma: no cover
1223
1223
index ['ignore_none' ] = index .pop ('ignoreNull' )
1224
1224
if 'selectivityEstimate' in index :
1225
1225
index ['selectivity' ] = index .pop ('selectivityEstimate' )
@@ -1255,7 +1255,7 @@ def response_handler(resp):
1255
1255
details ['min_length' ] = details .pop ('minLength' )
1256
1256
if 'geoJson' in details :
1257
1257
details ['geo_json' ] = details .pop ('geoJson' )
1258
- if 'ignoreNull' in details :
1258
+ if 'ignoreNull' in details : # pragma: no cover
1259
1259
details ['ignore_none' ] = details .pop ('ignoreNull' )
1260
1260
if 'selectivityEstimate' in details :
1261
1261
details ['selectivity' ] = details .pop ('selectivityEstimate' )
@@ -1496,7 +1496,13 @@ def response_handler(resp):
1496
1496
1497
1497
return self ._execute (request , response_handler )
1498
1498
1499
- def insert (self , document , return_new = False , sync = None , silent = False ):
1499
+ def insert (self ,
1500
+ document ,
1501
+ return_new = False ,
1502
+ sync = None ,
1503
+ silent = False ,
1504
+ overwrite = False ,
1505
+ return_old = False ):
1500
1506
"""Insert a new document.
1501
1507
1502
1508
:param document: Document to insert. If it contains the "_key" or "_id"
@@ -1511,14 +1517,25 @@ def insert(self, document, return_new=False, sync=None, silent=False):
1511
1517
:param silent: If set to True, no document metadata is returned. This
1512
1518
can be used to save resources.
1513
1519
:type silent: bool
1520
+ :param overwrite: If set to True, operation does not fail on duplicate
1521
+ key and the existing document is replaced.
1522
+ :type overwrite: bool
1523
+ :param return_old: Include body of the old document if replaced.
1524
+ Applies only when value of **overwrite** is set to True.
1525
+ :type return_old: bool
1514
1526
:return: Document metadata (e.g. document key, revision) or True if
1515
1527
parameter **silent** was set to True.
1516
1528
:rtype: bool | dict
1517
1529
:raise arango.exceptions.DocumentInsertError: If insert fails.
1518
1530
"""
1519
1531
document = self ._ensure_key_from_id (document )
1520
1532
1521
- params = {'returnNew' : return_new , 'silent' : silent }
1533
+ params = {
1534
+ 'returnNew' : return_new ,
1535
+ 'silent' : silent ,
1536
+ 'overwrite' : overwrite ,
1537
+ 'returnOld' : return_old
1538
+ }
1522
1539
if sync is not None :
1523
1540
params ['waitForSync' ] = sync
1524
1541
@@ -1540,15 +1557,21 @@ def insert(self, document, return_new=False, sync=None, silent=False):
1540
1557
def response_handler (resp ):
1541
1558
if not resp .is_success :
1542
1559
raise DocumentInsertError (resp , request )
1543
- return True if silent else resp .body
1560
+ if silent :
1561
+ return True
1562
+ if '_oldRev' in resp .body :
1563
+ resp .body ['_old_rev' ] = resp .body .pop ('_oldRev' )
1564
+ return resp .body
1544
1565
1545
1566
return self ._execute (request , response_handler )
1546
1567
1547
1568
def insert_many (self ,
1548
1569
documents ,
1549
1570
return_new = False ,
1550
1571
sync = None ,
1551
- silent = False ):
1572
+ silent = False ,
1573
+ overwrite = False ,
1574
+ return_old = False ):
1552
1575
"""Insert multiple documents.
1553
1576
1554
1577
If inserting a document fails, the exception object is placed in the
@@ -1566,14 +1589,25 @@ def insert_many(self,
1566
1589
:param silent: If set to True, no document metadata is returned. This
1567
1590
can be used to save resources.
1568
1591
:type silent: bool
1592
+ :param overwrite: If set to True, operation does not fail on duplicate
1593
+ keys and the existing documents are replaced.
1594
+ :type overwrite: bool
1595
+ :param return_old: Include body of the old documents if replaced.
1596
+ Applies only when value of **overwrite** is set to True.
1597
+ :type return_old: bool
1569
1598
:return: List of document metadata (e.g. document keys, revisions) and
1570
1599
any exception, or True if parameter **silent** was set to True.
1571
1600
:rtype: [dict | ArangoError] | bool
1572
1601
:raise arango.exceptions.DocumentInsertError: If insert fails.
1573
1602
"""
1574
1603
documents = [self ._ensure_key_from_id (doc ) for doc in documents ]
1575
1604
1576
- params = {'returnNew' : return_new , 'silent' : silent }
1605
+ params = {
1606
+ 'returnNew' : return_new ,
1607
+ 'silent' : silent ,
1608
+ 'overwrite' : overwrite ,
1609
+ 'returnOld' : return_old
1610
+ }
1577
1611
if sync is not None :
1578
1612
params ['waitForSync' ] = sync
1579
1613
@@ -1601,6 +1635,8 @@ def response_handler(resp):
1601
1635
results = []
1602
1636
for result in resp .body :
1603
1637
if '_id' in result :
1638
+ if '_oldRev' in result :
1639
+ result ['_old_rev' ] = result .pop ('_oldRev' )
1604
1640
results .append (result )
1605
1641
else :
1606
1642
sub_resp = Response (
@@ -1783,7 +1819,7 @@ def response_handler(resp):
1783
1819
)
1784
1820
if result ['errorNum' ] == 1200 :
1785
1821
result = DocumentRevisionError (sub_resp , request )
1786
- else :
1822
+ else : # pragma: no cover
1787
1823
result = DocumentUpdateError (sub_resp , request )
1788
1824
else :
1789
1825
result ['_old_rev' ] = result .pop ('_oldRev' )
@@ -2006,7 +2042,7 @@ def response_handler(resp):
2006
2042
)
2007
2043
if result ['errorNum' ] == 1200 :
2008
2044
result = DocumentRevisionError (sub_resp , request )
2009
- else :
2045
+ else : # pragma: no cover
2010
2046
result = DocumentReplaceError (sub_resp , request )
2011
2047
else :
2012
2048
result ['_old_rev' ] = result .pop ('_oldRev' )
@@ -2332,9 +2368,9 @@ def import_bulk(self,
2332
2368
params ['complete' ] = halt_on_error
2333
2369
if details is not None :
2334
2370
params ['details' ] = details
2335
- if from_prefix is not None :
2371
+ if from_prefix is not None : # pragma: no cover
2336
2372
params ['fromPrefix' ] = from_prefix
2337
- if to_prefix is not None :
2373
+ if to_prefix is not None : # pragma: no cover
2338
2374
params ['toPrefix' ] = to_prefix
2339
2375
if overwrite is not None :
2340
2376
params ['overwrite' ] = overwrite
@@ -2495,7 +2531,9 @@ def update(self,
2495
2531
check_rev = True ,
2496
2532
keep_none = True ,
2497
2533
sync = None ,
2498
- silent = False ):
2534
+ silent = False ,
2535
+ return_old = False ,
2536
+ return_new = False ):
2499
2537
"""Update a vertex document.
2500
2538
2501
2539
:param vertex: Partial or full vertex document with updated values. It
@@ -2523,7 +2561,9 @@ def update(self,
2523
2561
params = {
2524
2562
'keepNull' : keep_none ,
2525
2563
'overwrite' : not check_rev ,
2526
- 'silent' : silent
2564
+ 'silent' : silent ,
2565
+ 'returnNew' : return_new ,
2566
+ 'returnOld' : return_old
2527
2567
}
2528
2568
if sync is not None :
2529
2569
params ['waitForSync' ] = sync
@@ -2549,7 +2589,7 @@ def update(self,
2549
2589
)
2550
2590
2551
2591
def response_handler (resp ):
2552
- if resp .status_code == 412 :
2592
+ if resp .status_code == 412 : # pragma: no cover
2553
2593
raise DocumentRevisionError (resp , request )
2554
2594
elif not resp .is_success :
2555
2595
raise DocumentUpdateError (resp , request )
@@ -2611,7 +2651,7 @@ def replace(self, vertex, check_rev=True, sync=None, silent=False):
2611
2651
)
2612
2652
2613
2653
def response_handler (resp ):
2614
- if resp .status_code == 412 :
2654
+ if resp .status_code == 412 : # pragma: no cover
2615
2655
raise DocumentRevisionError (resp , request )
2616
2656
elif not resp .is_success :
2617
2657
raise DocumentReplaceError (resp , request )
@@ -2680,7 +2720,7 @@ def delete(self,
2680
2720
def response_handler (resp ):
2681
2721
if resp .error_code == 1202 and ignore_missing :
2682
2722
return False
2683
- if resp .status_code == 412 :
2723
+ if resp .status_code == 412 : # pragma: no cover
2684
2724
raise DocumentRevisionError (resp , request )
2685
2725
if not resp .is_success :
2686
2726
raise DocumentDeleteError (resp , request )
@@ -2759,7 +2799,7 @@ def get(self, edge, rev=None, check_rev=True):
2759
2799
def response_handler (resp ):
2760
2800
if resp .error_code == 1202 :
2761
2801
return None
2762
- if resp .status_code == 412 :
2802
+ if resp .status_code == 412 : # pragma: no cover
2763
2803
raise DocumentRevisionError (resp , request )
2764
2804
if not resp .is_success :
2765
2805
raise DocumentGetError (resp , request )
@@ -2883,7 +2923,7 @@ def update(self,
2883
2923
)
2884
2924
2885
2925
def response_handler (resp ):
2886
- if resp .status_code == 412 :
2926
+ if resp .status_code == 412 : # pragma: no cover
2887
2927
raise DocumentRevisionError (resp , request )
2888
2928
if not resp .is_success :
2889
2929
raise DocumentUpdateError (resp , request )
@@ -2946,7 +2986,7 @@ def replace(self, edge, check_rev=True, sync=None, silent=False):
2946
2986
)
2947
2987
2948
2988
def response_handler (resp ):
2949
- if resp .status_code == 412 :
2989
+ if resp .status_code == 412 : # pragma: no cover
2950
2990
raise DocumentRevisionError (resp , request )
2951
2991
if not resp .is_success :
2952
2992
raise DocumentReplaceError (resp , request )
@@ -3015,7 +3055,7 @@ def delete(self,
3015
3055
def response_handler (resp ):
3016
3056
if resp .error_code == 1202 and ignore_missing :
3017
3057
return False
3018
- if resp .status_code == 412 :
3058
+ if resp .status_code == 412 : # pragma: no cover
3019
3059
raise DocumentRevisionError (resp , request )
3020
3060
if not resp .is_success :
3021
3061
raise DocumentDeleteError (resp , request )
0 commit comments