Skip to content

Commit ed35c9d

Browse files
authored
[3.12]: External versioning support (#327)
* Initial commit * Fix lint * lint * lint * addressing comments * fix lint * wip * Added tests * цшз
1 parent d48bd79 commit ed35c9d

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

arango/collection.py

+38
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@ def insert_many(
17581758
keep_none: Optional[bool] = None,
17591759
merge: Optional[bool] = None,
17601760
refill_index_caches: Optional[bool] = None,
1761+
version_attribute: Optional[str] = None,
17611762
) -> Result[Union[bool, List[Union[Json, ArangoServerError]]]]:
17621763
"""Insert multiple documents.
17631764
@@ -1812,6 +1813,9 @@ def insert_many(
18121813
index caches if document insertions affect the edge index or
18131814
cache-enabled persistent indexes.
18141815
:type refill_index_caches: bool | None
1816+
param version_attribute: support for simple external versioning to
1817+
document operations.
1818+
:type version_attribute: str
18151819
:return: List of document metadata (e.g. document keys, revisions) and
18161820
any exception, or True if parameter **silent** was set to True.
18171821
:rtype: [dict | ArangoServerError] | bool
@@ -1834,6 +1838,8 @@ def insert_many(
18341838
params["keepNull"] = keep_none
18351839
if merge is not None:
18361840
params["mergeObjects"] = merge
1841+
if version_attribute is not None:
1842+
params["versionAttribute"] = version_attribute
18371843

18381844
# New in ArangoDB 3.9.6 and 3.10.2
18391845
if refill_index_caches is not None:
@@ -1880,6 +1886,7 @@ def update_many(
18801886
silent: bool = False,
18811887
refill_index_caches: Optional[bool] = None,
18821888
raise_on_document_error: bool = False,
1889+
version_attribute: Optional[str] = None,
18831890
) -> Result[Union[bool, List[Union[Json, ArangoServerError]]]]:
18841891
"""Update multiple documents.
18851892
@@ -1932,6 +1939,9 @@ def update_many(
19321939
as opposed to returning the error as an object in the result list.
19331940
Defaults to False.
19341941
:type raise_on_document_error: bool
1942+
param version_attribute: support for simple external versioning to
1943+
document operations.
1944+
:type version_attribute: str
19351945
:return: List of document metadata (e.g. document keys, revisions) and
19361946
any exceptions, or True if parameter **silent** was set to True.
19371947
:rtype: [dict | ArangoError] | bool
@@ -1948,6 +1958,8 @@ def update_many(
19481958
}
19491959
if sync is not None:
19501960
params["waitForSync"] = sync
1961+
if version_attribute is not None:
1962+
params["versionAttribute"] = version_attribute
19511963

19521964
# New in ArangoDB 3.9.6 and 3.10.2
19531965
if refill_index_caches is not None:
@@ -2084,6 +2096,7 @@ def replace_many(
20842096
sync: Optional[bool] = None,
20852097
silent: bool = False,
20862098
refill_index_caches: Optional[bool] = None,
2099+
version_attribute: Optional[str] = None,
20872100
) -> Result[Union[bool, List[Union[Json, ArangoServerError]]]]:
20882101
"""Replace multiple documents.
20892102
@@ -2125,6 +2138,9 @@ def replace_many(
21252138
index caches if document operations affect the edge index or
21262139
cache-enabled persistent indexes.
21272140
:type refill_index_caches: bool | None
2141+
param version_attribute: support for simple external versioning to
2142+
document operations.
2143+
:type version_attribute: str
21282144
:return: List of document metadata (e.g. document keys, revisions) and
21292145
any exceptions, or True if parameter **silent** was set to True.
21302146
:rtype: [dict | ArangoServerError] | bool
@@ -2139,6 +2155,8 @@ def replace_many(
21392155
}
21402156
if sync is not None:
21412157
params["waitForSync"] = sync
2158+
if version_attribute is not None:
2159+
params["versionAttribute"] = version_attribute
21422160

21432161
# New in ArangoDB 3.9.6 and 3.10.2
21442162
if refill_index_caches is not None:
@@ -2613,6 +2631,7 @@ def insert(
26132631
keep_none: Optional[bool] = None,
26142632
merge: Optional[bool] = None,
26152633
refill_index_caches: Optional[bool] = None,
2634+
version_attribute: Optional[str] = None,
26162635
) -> Result[Union[bool, Json]]:
26172636
"""Insert a new document.
26182637
@@ -2651,6 +2670,9 @@ def insert(
26512670
index caches if document insertions affect the edge index or
26522671
cache-enabled persistent indexes.
26532672
:type refill_index_caches: bool | None
2673+
param version_attribute: support for simple external versioning to
2674+
document operations.
2675+
:type version_attribute: str
26542676
:return: Document metadata (e.g. document key, revision) or True if
26552677
parameter **silent** was set to True.
26562678
:rtype: bool | dict
@@ -2672,6 +2694,8 @@ def insert(
26722694
params["keepNull"] = keep_none
26732695
if merge is not None:
26742696
params["mergeObjects"] = merge
2697+
if version_attribute is not None:
2698+
params["versionAttribute"] = version_attribute
26752699

26762700
# New in ArangoDB 3.9.6 and 3.10.2
26772701
if refill_index_caches is not None:
@@ -2710,6 +2734,7 @@ def update(
27102734
sync: Optional[bool] = None,
27112735
silent: bool = False,
27122736
refill_index_caches: Optional[bool] = None,
2737+
version_attribute: Optional[str] = None,
27132738
) -> Result[Union[bool, Json]]:
27142739
"""Update a document.
27152740
@@ -2740,6 +2765,9 @@ def update(
27402765
index caches if document insertions affect the edge index or
27412766
cache-enabled persistent indexes.
27422767
:type refill_index_caches: bool | None
2768+
param version_attribute: support for simple external versioning
2769+
to document operations.
2770+
:type version_attribute: str
27432771
:return: Document metadata (e.g. document key, revision) or True if
27442772
parameter **silent** was set to True.
27452773
:rtype: bool | dict
@@ -2758,6 +2786,9 @@ def update(
27582786
if sync is not None:
27592787
params["waitForSync"] = sync
27602788

2789+
if version_attribute is not None:
2790+
params["versionAttribute"] = version_attribute
2791+
27612792
# New in ArangoDB 3.9.6 and 3.10.2
27622793
if refill_index_caches is not None:
27632794
params["refillIndexCaches"] = refill_index_caches
@@ -2793,6 +2824,7 @@ def replace(
27932824
sync: Optional[bool] = None,
27942825
silent: bool = False,
27952826
refill_index_caches: Optional[bool] = None,
2827+
version_attribute: Optional[str] = None,
27962828
) -> Result[Union[bool, Json]]:
27972829
"""Replace a document.
27982830
@@ -2818,6 +2850,9 @@ def replace(
28182850
index caches if document insertions affect the edge index or
28192851
cache-enabled persistent indexes.
28202852
:type refill_index_caches: bool | None
2853+
param version_attribute: support for simple external versioning to
2854+
document operations.
2855+
:type version_attribute: str
28212856
:return: Document metadata (e.g. document key, revision) or True if
28222857
parameter **silent** was set to True.
28232858
:rtype: bool | dict
@@ -2834,6 +2869,9 @@ def replace(
28342869
if sync is not None:
28352870
params["waitForSync"] = sync
28362871

2872+
if version_attribute is not None:
2873+
params["versionAttribute"] = version_attribute
2874+
28372875
# New in ArangoDB 3.9.6 and 3.10.2
28382876
if refill_index_caches is not None:
28392877
params["refillIndexCaches"] = refill_index_caches

tests/test_document.py

+72
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from packaging import version
23

34
from arango.exceptions import (
45
DocumentCountError,
@@ -2067,3 +2068,74 @@ def test_document_management_via_db(db, col):
20672068
assert result["_id"] == doc1_id
20682069
assert doc1_id not in col
20692070
assert len(col) == 2
2071+
2072+
2073+
def test_version_attributes_update_many(col, db_version):
2074+
if db_version < version.parse("3.12.0"):
2075+
pytest.skip("Version attributes is tested in 3.12.0+")
2076+
2077+
col.insert_many(
2078+
[
2079+
{"_key": "test1", "version": 0},
2080+
{"_key": "test2", "version": 0},
2081+
{"_key": "test3", "version": 0},
2082+
]
2083+
)
2084+
2085+
docs = [
2086+
{"_key": "test1", "version": 2},
2087+
{"_key": "test1", "version": 3},
2088+
{"_key": "test1", "version": 1},
2089+
{"_key": "test2", "version": 1},
2090+
{"_key": "test2", "version": 9},
2091+
{"_key": "test2", "version": 42},
2092+
{"_key": "test2", "version": 0},
2093+
{"_key": "test3"},
2094+
{"_key": "test3", "version": 5},
2095+
{"_key": "test3", "version": 4},
2096+
{"_key": "test3", "value": 2},
2097+
]
2098+
2099+
col.update_many(docs, version_attribute="version")
2100+
assert col["test1"]["version"] == 3
2101+
assert col["test2"]["version"] == 42
2102+
assert col["test3"]["version"] == 5
2103+
2104+
docs = [
2105+
{"_key": "test1", "version": 2},
2106+
{"_key": "test1", "version": 3},
2107+
{"_key": "test1", "version": 5},
2108+
{"_key": "test2", "version": 1},
2109+
{"_key": "test2", "version": 9},
2110+
{"_key": "test2", "version": 42},
2111+
{"_key": "test2", "version": 0},
2112+
{"_key": "test3", "version": 5},
2113+
{"_key": "test3", "version": 6},
2114+
]
2115+
2116+
col.replace_many(docs, version_attribute="version")
2117+
assert col["test1"]["version"] == 5
2118+
assert col["test2"]["version"] == 42
2119+
assert col["test3"]["version"] == 6
2120+
2121+
docs = [
2122+
{"_key": "test1", "version": 0},
2123+
{"_key": "test2", "version": 0},
2124+
{"_key": "test3", "version": 0},
2125+
]
2126+
2127+
col.insert_many(docs, overwrite_mode="update", version_attribute="version")
2128+
assert col["test1"]["version"] == 5
2129+
assert col["test2"]["version"] == 42
2130+
assert col["test3"]["version"] == 6
2131+
2132+
docs = [
2133+
{"_key": "test1", "version": 43},
2134+
{"_key": "test2", "version": 41},
2135+
{"_key": "test3", "version": 43},
2136+
]
2137+
2138+
col.insert_many(docs, overwrite_mode="replace", version_attribute="version")
2139+
assert col["test1"]["version"] == 43
2140+
assert col["test2"]["version"] == 42
2141+
assert col["test3"]["version"] == 43

0 commit comments

Comments
 (0)