@@ -511,6 +511,7 @@ def has(
511511 document : Union [str , Json ],
512512 rev : Optional [str ] = None ,
513513 check_rev : bool = True ,
514+ allow_dirty_read : bool = False ,
514515 ) -> Result [bool ]:
515516 """Check if a document exists in the collection.
516517
@@ -523,13 +524,18 @@ def has(
523524 :param check_rev: If set to True, revision of **document** (if given)
524525 is compared against the revision of target document.
525526 :type check_rev: bool
527+ :param allow_dirty_read: Allow reads from followers in a cluster.
528+ :type allow_dirty_read: bool | None
526529 :return: True if document exists, False otherwise.
527530 :rtype: bool
528531 :raise arango.exceptions.DocumentInError: If check fails.
529532 :raise arango.exceptions.DocumentRevisionError: If revisions mismatch.
530533 """
531534 handle , body , headers = self ._prep_from_doc (document , rev , check_rev )
532535
536+ if allow_dirty_read :
537+ headers ["x-arango-allow-dirty-read" ] = "true"
538+
533539 request = Request (
534540 method = "get" ,
535541 endpoint = f"/_api/document/{ handle } " ,
@@ -662,7 +668,11 @@ def response_handler(resp: Response) -> Cursor:
662668 return self ._execute (request , response_handler )
663669
664670 def find_near (
665- self , latitude : Number , longitude : Number , limit : Optional [int ] = None
671+ self ,
672+ latitude : Number ,
673+ longitude : Number ,
674+ limit : Optional [int ] = None ,
675+ allow_dirty_read : bool = False ,
666676 ) -> Result [Cursor ]:
667677 """Return documents near a given coordinate.
668678
@@ -677,6 +687,8 @@ def find_near(
677687 :type longitude: int | float
678688 :param limit: Max number of documents returned.
679689 :type limit: int | None
690+ :param allow_dirty_read: Allow reads from followers in a cluster.
691+ :type allow_dirty_read: bool | None
680692 :returns: Document cursor.
681693 :rtype: arango.cursor.Cursor
682694 :raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -705,6 +717,7 @@ def find_near(
705717 endpoint = "/_api/cursor" ,
706718 data = {"query" : query , "bindVars" : bind_vars , "count" : True },
707719 read = self .name ,
720+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
708721 )
709722
710723 def response_handler (resp : Response ) -> Cursor :
@@ -721,6 +734,7 @@ def find_in_range(
721734 upper : int ,
722735 skip : Optional [int ] = None ,
723736 limit : Optional [int ] = None ,
737+ allow_dirty_read : bool = False ,
724738 ) -> Result [Cursor ]:
725739 """Return documents within a given range in a random order.
726740
@@ -736,6 +750,8 @@ def find_in_range(
736750 :type skip: int | None
737751 :param limit: Max number of documents returned.
738752 :type limit: int | None
753+ :param allow_dirty_read: Allow reads from followers in a cluster.
754+ :type allow_dirty_read: bool | None
739755 :returns: Document cursor.
740756 :rtype: arango.cursor.Cursor
741757 :raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -764,6 +780,7 @@ def find_in_range(
764780 endpoint = "/_api/cursor" ,
765781 data = {"query" : query , "bindVars" : bind_vars , "count" : True },
766782 read = self .name ,
783+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
767784 )
768785
769786 def response_handler (resp : Response ) -> Cursor :
@@ -779,6 +796,7 @@ def find_in_radius(
779796 longitude : Number ,
780797 radius : Number ,
781798 distance_field : Optional [str ] = None ,
799+ allow_dirty_read : bool = False ,
782800 ) -> Result [Cursor ]:
783801 """Return documents within a given radius around a coordinate.
784802
@@ -793,6 +811,8 @@ def find_in_radius(
793811 :param distance_field: Document field used to indicate the distance to
794812 the given coordinate. This parameter is ignored in transactions.
795813 :type distance_field: str
814+ :param allow_dirty_read: Allow reads from followers in a cluster.
815+ :type allow_dirty_read: bool | None
796816 :returns: Document cursor.
797817 :rtype: arango.cursor.Cursor
798818 :raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -823,6 +843,7 @@ def find_in_radius(
823843 endpoint = "/_api/cursor" ,
824844 data = {"query" : query , "bindVars" : bind_vars , "count" : True },
825845 read = self .name ,
846+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
826847 )
827848
828849 def response_handler (resp : Response ) -> Cursor :
@@ -899,7 +920,11 @@ def response_handler(resp: Response) -> Cursor:
899920 return self ._execute (request , response_handler )
900921
901922 def find_by_text (
902- self , field : str , query : str , limit : Optional [int ] = None
923+ self ,
924+ field : str ,
925+ query : str ,
926+ limit : Optional [int ] = None ,
927+ allow_dirty_read : bool = False ,
903928 ) -> Result [Cursor ]:
904929 """Return documents that match the given fulltext query.
905930
@@ -909,6 +934,8 @@ def find_by_text(
909934 :type query: str
910935 :param limit: Max number of documents returned.
911936 :type limit: int | None
937+ :param allow_dirty_read: Allow reads from followers in a cluster.
938+ :type allow_dirty_read: bool | None
912939 :returns: Document cursor.
913940 :rtype: arango.cursor.Cursor
914941 :raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -935,6 +962,7 @@ def find_by_text(
935962 endpoint = "/_api/cursor" ,
936963 data = {"query" : aql , "bindVars" : bind_vars , "count" : True },
937964 read = self .name ,
965+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
938966 )
939967
940968 def response_handler (resp : Response ) -> Cursor :
@@ -944,12 +972,18 @@ def response_handler(resp: Response) -> Cursor:
944972
945973 return self ._execute (request , response_handler )
946974
947- def get_many (self , documents : Sequence [Union [str , Json ]]) -> Result [List [Json ]]:
975+ def get_many (
976+ self ,
977+ documents : Sequence [Union [str , Json ]],
978+ allow_dirty_read : bool = False ,
979+ ) -> Result [List [Json ]]:
948980 """Return multiple documents ignoring any missing ones.
949981
950982 :param documents: List of document keys, IDs or bodies. Document bodies
951983 must contain the "_id" or "_key" fields.
952984 :type documents: [str | dict]
985+ :param allow_dirty_read: Allow reads from followers in a cluster.
986+ :type allow_dirty_read: bool | None
953987 :return: Documents. Missing ones are not included.
954988 :rtype: [dict]
955989 :raise arango.exceptions.DocumentGetError: If retrieval fails.
@@ -964,6 +998,7 @@ def get_many(self, documents: Sequence[Union[str, Json]]) -> Result[List[Json]]:
964998 params = params ,
965999 data = handles ,
9661000 read = self .name ,
1001+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
9671002 )
9681003
9691004 def response_handler (resp : Response ) -> List [Json ]:
@@ -2123,6 +2158,7 @@ def get(
21232158 document : Union [str , Json ],
21242159 rev : Optional [str ] = None ,
21252160 check_rev : bool = True ,
2161+ allow_dirty_read : bool = False ,
21262162 ) -> Result [Optional [Json ]]:
21272163 """Return a document.
21282164
@@ -2135,13 +2171,18 @@ def get(
21352171 :param check_rev: If set to True, revision of **document** (if given)
21362172 is compared against the revision of target document.
21372173 :type check_rev: bool
2174+ :param allow_dirty_read: Allow reads from followers in a cluster.
2175+ :type allow_dirty_read: bool | None
21382176 :return: Document, or None if not found.
21392177 :rtype: dict | None
21402178 :raise arango.exceptions.DocumentGetError: If retrieval fails.
21412179 :raise arango.exceptions.DocumentRevisionError: If revisions mismatch.
21422180 """
21432181 handle , body , headers = self ._prep_from_doc (document , rev , check_rev )
21442182
2183+ if allow_dirty_read :
2184+ headers ["x-arango-allow-dirty-read" ] = "true"
2185+
21452186 request = Request (
21462187 method = "get" ,
21472188 endpoint = f"/_api/document/{ handle } " ,
@@ -3144,7 +3185,10 @@ def link(
31443185 return self .insert (edge , sync = sync , silent = silent , return_new = return_new )
31453186
31463187 def edges (
3147- self , vertex : Union [str , Json ], direction : Optional [str ] = None
3188+ self ,
3189+ vertex : Union [str , Json ],
3190+ direction : Optional [str ] = None ,
3191+ allow_dirty_read : bool = False ,
31483192 ) -> Result [Json ]:
31493193 """Return the edge documents coming in and/or out of the vertex.
31503194
@@ -3153,6 +3197,8 @@ def edges(
31533197 :param direction: The direction of the edges. Allowed values are "in"
31543198 and "out". If not set, edges in both directions are returned.
31553199 :type direction: str
3200+ :param allow_dirty_read: Allow reads from followers in a cluster.
3201+ :type allow_dirty_read: bool | None
31563202 :return: List of edges and statistics.
31573203 :rtype: dict
31583204 :raise arango.exceptions.EdgeListError: If retrieval fails.
@@ -3166,6 +3212,7 @@ def edges(
31663212 endpoint = f"/_api/edges/{ self .name } " ,
31673213 params = params ,
31683214 read = self .name ,
3215+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
31693216 )
31703217
31713218 def response_handler (resp : Response ) -> Json :
0 commit comments