Skip to content

Commit 73e54cf

Browse files
committed
Adding support for /revision
1 parent 3ea1d35 commit 73e54cf

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

arangoasync/collection.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from arangoasync.exceptions import (
1919
CollectionPropertiesError,
2020
CollectionResponsibleShardError,
21+
CollectionRevisionError,
2122
CollectionShardsError,
2223
CollectionStatisticsError,
2324
CollectionTruncateError,
@@ -638,7 +639,7 @@ async def shards(self, details: Optional[bool] = None) -> Result[Json]:
638639
servers for these shards.
639640
640641
Returns:
641-
dict: Collection shards and properties.
642+
dict: Collection shards.
642643
643644
Raises:
644645
CollectionShardsError: If retrieval fails.
@@ -659,7 +660,31 @@ async def shards(self, details: Optional[bool] = None) -> Result[Json]:
659660
def response_handler(resp: Response) -> Json:
660661
if not resp.is_success:
661662
raise CollectionShardsError(resp, request)
662-
return Response.format_body(self.deserializer.loads(resp.raw_body))
663+
return cast(Json, self.deserializer.loads(resp.raw_body)["shards"])
664+
665+
return await self._executor.execute(request, response_handler)
666+
667+
async def revision(self) -> Result[str]:
668+
"""Return collection revision.
669+
670+
Returns:
671+
str: Collection revision.
672+
673+
Raises:
674+
CollectionRevisionError: If retrieval fails.
675+
676+
References:
677+
- `get-the-collection-revision-id <https://docs.arangodb.com/stable/develop/http-api/collections/#get-the-collection-revision-id>`__
678+
""" # noqa: E501
679+
request = Request(
680+
method=Method.GET,
681+
endpoint=f"/_api/collection/{self.name}/revision",
682+
)
683+
684+
def response_handler(resp: Response) -> str:
685+
if not resp.is_success:
686+
raise CollectionRevisionError(resp, request)
687+
return cast(str, self.deserializer.loads(resp.raw_body)["revision"])
663688

664689
return await self._executor.execute(request, response_handler)
665690

arangoasync/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ class CollectionResponsibleShardError(ArangoServerError):
199199
"""Failed to retrieve responsible shard."""
200200

201201

202+
class CollectionRevisionError(ArangoServerError):
203+
"""Failed to retrieve collection revision."""
204+
205+
202206
class CollectionShardsError(ArangoServerError):
203207
"""Failed to retrieve collection shards."""
204208

tests/test_collection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from arangoasync.exceptions import (
77
CollectionPropertiesError,
88
CollectionResponsibleShardError,
9+
CollectionRevisionError,
910
CollectionShardsError,
1011
CollectionStatisticsError,
1112
CollectionTruncateError,
@@ -53,6 +54,12 @@ async def test_collection_misc_methods(doc_col, bad_col, docs, cluster):
5354
with pytest.raises(CollectionShardsError):
5455
await bad_col.shards()
5556

57+
# Revision
58+
revision = await doc_col.revision()
59+
assert isinstance(revision, str)
60+
with pytest.raises(CollectionRevisionError):
61+
await bad_col.revision()
62+
5663

5764
@pytest.mark.asyncio
5865
async def test_collection_index(doc_col, bad_col, cluster):

0 commit comments

Comments
 (0)