@@ -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 : Optional [bool ] = None ,
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 : Optional [bool ] = None ,
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 : Optional [bool ] = None ,
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 : Optional [bool ] = None ,
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 : Optional [bool ] = None ,
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 : Optional [bool ] = None ,
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 ]:
@@ -2054,6 +2089,7 @@ def get(
2054
2089
document : Union [str , Json ],
2055
2090
rev : Optional [str ] = None ,
2056
2091
check_rev : bool = True ,
2092
+ allow_dirty_read : Optional [bool ] = None ,
2057
2093
) -> Result [Optional [Json ]]:
2058
2094
"""Return a document.
2059
2095
@@ -2066,13 +2102,18 @@ def get(
2066
2102
:param check_rev: If set to True, revision of **document** (if given)
2067
2103
is compared against the revision of target document.
2068
2104
:type check_rev: bool
2105
+ :param allow_dirty_read: Allow reads from followers in a cluster.
2106
+ :type allow_dirty_read: bool | None
2069
2107
:return: Document, or None if not found.
2070
2108
:rtype: dict | None
2071
2109
:raise arango.exceptions.DocumentGetError: If retrieval fails.
2072
2110
:raise arango.exceptions.DocumentRevisionError: If revisions mismatch.
2073
2111
"""
2074
2112
handle , body , headers = self ._prep_from_doc (document , rev , check_rev )
2075
2113
2114
+ if allow_dirty_read :
2115
+ headers ["x-arango-allow-dirty-read" ] = "true"
2116
+
2076
2117
request = Request (
2077
2118
method = "get" ,
2078
2119
endpoint = f"/_api/document/{ handle } " ,
@@ -3075,7 +3116,10 @@ def link(
3075
3116
return self .insert (edge , sync = sync , silent = silent , return_new = return_new )
3076
3117
3077
3118
def edges (
3078
- self , vertex : Union [str , Json ], direction : Optional [str ] = None
3119
+ self ,
3120
+ vertex : Union [str , Json ],
3121
+ direction : Optional [str ] = None ,
3122
+ allow_dirty_read : Optional [bool ] = None ,
3079
3123
) -> Result [Json ]:
3080
3124
"""Return the edge documents coming in and/or out of the vertex.
3081
3125
@@ -3084,6 +3128,8 @@ def edges(
3084
3128
:param direction: The direction of the edges. Allowed values are "in"
3085
3129
and "out". If not set, edges in both directions are returned.
3086
3130
:type direction: str
3131
+ :param allow_dirty_read: Allow reads from followers in a cluster.
3132
+ :type allow_dirty_read: bool | None
3087
3133
:return: List of edges and statistics.
3088
3134
:rtype: dict
3089
3135
:raise arango.exceptions.EdgeListError: If retrieval fails.
@@ -3097,6 +3143,7 @@ def edges(
3097
3143
endpoint = f"/_api/edges/{ self .name } " ,
3098
3144
params = params ,
3099
3145
read = self .name ,
3146
+ headers = {"x-arango-allow-dirty-read" : "true" } if allow_dirty_read else None ,
3100
3147
)
3101
3148
3102
3149
def response_handler (resp : Response ) -> Json :
0 commit comments