@@ -511,6 +511,7 @@ def has(
511
511
document : Union [str , Json ],
512
512
rev : Optional [str ] = None ,
513
513
check_rev : bool = True ,
514
+ allow_dirty_read : bool = False ,
514
515
) -> Result [bool ]:
515
516
"""Check if a document exists in the collection.
516
517
@@ -523,13 +524,18 @@ def has(
523
524
:param check_rev: If set to True, revision of **document** (if given)
524
525
is compared against the revision of target document.
525
526
:type check_rev: bool
527
+ :param allow_dirty_read: Allow reads from followers in a cluster.
528
+ :type allow_dirty_read: bool | None
526
529
:return: True if document exists, False otherwise.
527
530
:rtype: bool
528
531
:raise arango.exceptions.DocumentInError: If check fails.
529
532
:raise arango.exceptions.DocumentRevisionError: If revisions mismatch.
530
533
"""
531
534
handle , body , headers = self ._prep_from_doc (document , rev , check_rev )
532
535
536
+ if allow_dirty_read :
537
+ headers ["x-arango-allow-dirty-read" ] = "true"
538
+
533
539
request = Request (
534
540
method = "get" ,
535
541
endpoint = f"/_api/document/{ handle } " ,
@@ -662,7 +668,11 @@ def response_handler(resp: Response) -> Cursor:
662
668
return self ._execute (request , response_handler )
663
669
664
670
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 ,
666
676
) -> Result [Cursor ]:
667
677
"""Return documents near a given coordinate.
668
678
@@ -677,6 +687,8 @@ def find_near(
677
687
:type longitude: int | float
678
688
:param limit: Max number of documents returned.
679
689
:type limit: int | None
690
+ :param allow_dirty_read: Allow reads from followers in a cluster.
691
+ :type allow_dirty_read: bool | None
680
692
:returns: Document cursor.
681
693
:rtype: arango.cursor.Cursor
682
694
:raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -705,6 +717,7 @@ def find_near(
705
717
endpoint = "/_api/cursor" ,
706
718
data = {"query" : query , "bindVars" : bind_vars , "count" : True },
707
719
read = self .name ,
720
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
708
721
)
709
722
710
723
def response_handler (resp : Response ) -> Cursor :
@@ -721,6 +734,7 @@ def find_in_range(
721
734
upper : int ,
722
735
skip : Optional [int ] = None ,
723
736
limit : Optional [int ] = None ,
737
+ allow_dirty_read : bool = False ,
724
738
) -> Result [Cursor ]:
725
739
"""Return documents within a given range in a random order.
726
740
@@ -736,6 +750,8 @@ def find_in_range(
736
750
:type skip: int | None
737
751
:param limit: Max number of documents returned.
738
752
:type limit: int | None
753
+ :param allow_dirty_read: Allow reads from followers in a cluster.
754
+ :type allow_dirty_read: bool | None
739
755
:returns: Document cursor.
740
756
:rtype: arango.cursor.Cursor
741
757
:raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -764,6 +780,7 @@ def find_in_range(
764
780
endpoint = "/_api/cursor" ,
765
781
data = {"query" : query , "bindVars" : bind_vars , "count" : True },
766
782
read = self .name ,
783
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
767
784
)
768
785
769
786
def response_handler (resp : Response ) -> Cursor :
@@ -779,6 +796,7 @@ def find_in_radius(
779
796
longitude : Number ,
780
797
radius : Number ,
781
798
distance_field : Optional [str ] = None ,
799
+ allow_dirty_read : bool = False ,
782
800
) -> Result [Cursor ]:
783
801
"""Return documents within a given radius around a coordinate.
784
802
@@ -793,6 +811,8 @@ def find_in_radius(
793
811
:param distance_field: Document field used to indicate the distance to
794
812
the given coordinate. This parameter is ignored in transactions.
795
813
:type distance_field: str
814
+ :param allow_dirty_read: Allow reads from followers in a cluster.
815
+ :type allow_dirty_read: bool | None
796
816
:returns: Document cursor.
797
817
:rtype: arango.cursor.Cursor
798
818
:raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -823,6 +843,7 @@ def find_in_radius(
823
843
endpoint = "/_api/cursor" ,
824
844
data = {"query" : query , "bindVars" : bind_vars , "count" : True },
825
845
read = self .name ,
846
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
826
847
)
827
848
828
849
def response_handler (resp : Response ) -> Cursor :
@@ -899,7 +920,11 @@ def response_handler(resp: Response) -> Cursor:
899
920
return self ._execute (request , response_handler )
900
921
901
922
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 ,
903
928
) -> Result [Cursor ]:
904
929
"""Return documents that match the given fulltext query.
905
930
@@ -909,6 +934,8 @@ def find_by_text(
909
934
:type query: str
910
935
:param limit: Max number of documents returned.
911
936
:type limit: int | None
937
+ :param allow_dirty_read: Allow reads from followers in a cluster.
938
+ :type allow_dirty_read: bool | None
912
939
:returns: Document cursor.
913
940
:rtype: arango.cursor.Cursor
914
941
:raises arango.exceptions.DocumentGetError: If retrieval fails.
@@ -935,6 +962,7 @@ def find_by_text(
935
962
endpoint = "/_api/cursor" ,
936
963
data = {"query" : aql , "bindVars" : bind_vars , "count" : True },
937
964
read = self .name ,
965
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
938
966
)
939
967
940
968
def response_handler (resp : Response ) -> Cursor :
@@ -944,12 +972,18 @@ def response_handler(resp: Response) -> Cursor:
944
972
945
973
return self ._execute (request , response_handler )
946
974
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 ]]:
948
980
"""Return multiple documents ignoring any missing ones.
949
981
950
982
:param documents: List of document keys, IDs or bodies. Document bodies
951
983
must contain the "_id" or "_key" fields.
952
984
:type documents: [str | dict]
985
+ :param allow_dirty_read: Allow reads from followers in a cluster.
986
+ :type allow_dirty_read: bool | None
953
987
:return: Documents. Missing ones are not included.
954
988
:rtype: [dict]
955
989
:raise arango.exceptions.DocumentGetError: If retrieval fails.
@@ -964,6 +998,7 @@ def get_many(self, documents: Sequence[Union[str, Json]]) -> Result[List[Json]]:
964
998
params = params ,
965
999
data = handles ,
966
1000
read = self .name ,
1001
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
967
1002
)
968
1003
969
1004
def response_handler (resp : Response ) -> List [Json ]:
@@ -2123,6 +2158,7 @@ def get(
2123
2158
document : Union [str , Json ],
2124
2159
rev : Optional [str ] = None ,
2125
2160
check_rev : bool = True ,
2161
+ allow_dirty_read : bool = False ,
2126
2162
) -> Result [Optional [Json ]]:
2127
2163
"""Return a document.
2128
2164
@@ -2135,13 +2171,18 @@ def get(
2135
2171
:param check_rev: If set to True, revision of **document** (if given)
2136
2172
is compared against the revision of target document.
2137
2173
:type check_rev: bool
2174
+ :param allow_dirty_read: Allow reads from followers in a cluster.
2175
+ :type allow_dirty_read: bool | None
2138
2176
:return: Document, or None if not found.
2139
2177
:rtype: dict | None
2140
2178
:raise arango.exceptions.DocumentGetError: If retrieval fails.
2141
2179
:raise arango.exceptions.DocumentRevisionError: If revisions mismatch.
2142
2180
"""
2143
2181
handle , body , headers = self ._prep_from_doc (document , rev , check_rev )
2144
2182
2183
+ if allow_dirty_read :
2184
+ headers ["x-arango-allow-dirty-read" ] = "true"
2185
+
2145
2186
request = Request (
2146
2187
method = "get" ,
2147
2188
endpoint = f"/_api/document/{ handle } " ,
@@ -3144,7 +3185,10 @@ def link(
3144
3185
return self .insert (edge , sync = sync , silent = silent , return_new = return_new )
3145
3186
3146
3187
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 ,
3148
3192
) -> Result [Json ]:
3149
3193
"""Return the edge documents coming in and/or out of the vertex.
3150
3194
@@ -3153,6 +3197,8 @@ def edges(
3153
3197
:param direction: The direction of the edges. Allowed values are "in"
3154
3198
and "out". If not set, edges in both directions are returned.
3155
3199
:type direction: str
3200
+ :param allow_dirty_read: Allow reads from followers in a cluster.
3201
+ :type allow_dirty_read: bool | None
3156
3202
:return: List of edges and statistics.
3157
3203
:rtype: dict
3158
3204
:raise arango.exceptions.EdgeListError: If retrieval fails.
@@ -3166,6 +3212,7 @@ def edges(
3166
3212
endpoint = f"/_api/edges/{ self .name } " ,
3167
3213
params = params ,
3168
3214
read = self .name ,
3215
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
3169
3216
)
3170
3217
3171
3218
def response_handler (resp : Response ) -> Json :
0 commit comments