@@ -27,6 +27,10 @@ class Cursor:
2727 :type init_data: dict
2828 :param cursor_type: Cursor type ("cursor" or "export").
2929 :type cursor_type: str
30+ :param allow_retry: If set to True, the cursor will always attempt to fetch
31+ the latest batch from server even if the previous attempt failed.
32+ This option is only available for server versions 3.11 and above.
33+ :type allow_retry: bool
3034 """
3135
3236 __slots__ = [
@@ -41,16 +45,19 @@ class Cursor:
4145 "_has_more" ,
4246 "_batch" ,
4347 "_next_batch_id" ,
48+ "_allow_retry" ,
4449 ]
4550
4651 def __init__ (
4752 self ,
4853 connection : BaseConnection ,
4954 init_data : Json ,
5055 cursor_type : str = "cursor" ,
56+ allow_retry : bool = False ,
5157 ) -> None :
5258 self ._conn = connection
5359 self ._type = cursor_type
60+ self ._allow_retry = allow_retry
5461 self ._batch : Deque [Any ] = deque ()
5562 self ._id = None
5663 self ._count : Optional [int ] = None
@@ -103,8 +110,10 @@ def _update(self, data: Json) -> Json:
103110
104111 # New in 3.11
105112 if "nextBatchId" in data :
106- self ._next_batch_id = data ["nextBatchId" ]
107- result ["next_batch_id" ] = data ["nextBatchId" ]
113+ # This is only available for server versions 3.11 and above.
114+ # Currently, we are testing against 3.10.9
115+ self ._next_batch_id = data ["nextBatchId" ] # pragma: no cover
116+ result ["next_batch_id" ] = data ["nextBatchId" ] # pragma: no cover
108117
109118 self ._has_more = bool (data ["hasMore" ])
110119 result ["has_more" ] = data ["hasMore" ]
@@ -280,33 +289,12 @@ def fetch(self) -> Json:
280289 """
281290 if self ._id is None :
282291 raise CursorStateError ("cursor ID not set" )
283- request = Request (method = "post" , endpoint = f"/_api/{ self ._type } /{ self ._id } " )
284- resp = self ._conn .send_request (request )
285-
286- if not resp .is_success :
287- raise CursorNextError (resp , request )
288292
289- return self ._update (resp .body )
290-
291- def retry (self ) -> Json :
292- """Retry fetching the next batch from server and update the cursor.
293+ endpoint = f"/_api/{ self ._type } /{ self ._id } "
294+ if self ._allow_retry and self ._next_batch_id is not None :
295+ endpoint += f"/{ self ._next_batch_id } " # pragma: no cover
293296
294- Available only if the ``allowRetry`` query options is enabled.
295- Introduced in 3.11.
296-
297- :return: New batch details.
298- :rtype: dict
299- :raise arango.exceptions.CursorNextError: If batch retrieval fails.
300- :raise arango.exceptions.CursorStateError: If cursor ID is not set.
301- """
302- if self ._id is None :
303- raise CursorStateError ("cursor ID not set" )
304- if self ._id is None :
305- raise CursorStateError ("nextBatchId not set" )
306- request = Request (
307- method = "post" ,
308- endpoint = f"/_api/{ self ._type } /{ self ._id } /{ self ._next_batch_id } " ,
309- )
297+ request = Request (method = "post" , endpoint = endpoint )
310298 resp = self ._conn .send_request (request )
311299
312300 if not resp .is_success :
0 commit comments