From 032929ccc55c8eb067ae8eb5219cc39041fa5fcd Mon Sep 17 00:00:00 2001 From: tjoubert Date: Fri, 5 Aug 2022 20:45:02 +0400 Subject: [PATCH 1/4] Added request_timeout property to client and parameter to its constructor. --- arango/client.py | 28 ++++++++++++++++++++++++++++ tests/test_client.py | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arango/client.py b/arango/client.py index 8424ddfa..ab04e5b1 100644 --- a/arango/client.py +++ b/arango/client.py @@ -53,6 +53,13 @@ class ArangoClient: False: Do not verify TLS certificate. str: Path to a custom CA bundle file or directory. :type verify_override: Union[bool, str, None] + :param request_timeout: This is the default request timeout (in seconds) + for http requests issued by the client. The default value is -1. + Setting this parameter to any other value, will overwrite your + request timeout set in the http client. + None: No timeout. + int: Timeout value in seconds. + :type request_timeout: Optional[int] """ def __init__( @@ -64,6 +71,7 @@ def __init__( serializer: Callable[..., str] = lambda x: dumps(x), deserializer: Callable[[str], Any] = lambda x: loads(x), verify_override: Union[bool, str, None] = None, + request_timeout: Any = -1, ) -> None: if isinstance(hosts, str): self._hosts = [host.strip("/") for host in hosts.split(",")] @@ -80,7 +88,13 @@ def __init__( else: self._host_resolver = RoundRobinHostResolver(host_count, resolver_max_tries) + # Initializes the http client self._http = http_client or DefaultHTTPClient() + # Sets the request timeout. + # This call can only happen AFTER initializing the http client. + if request_timeout != -1: + self.request_timeout = request_timeout + self._serializer = serializer self._deserializer = deserializer self._sessions = [self._http.create_session(h) for h in self._hosts] @@ -117,6 +131,20 @@ def version(self) -> str: version: str = get_distribution("python-arango").version return version + @property + def request_timeout(self) -> Any: + """Return the request timeout of the http client. + + :return: Request timeout. + :rtype: Any + """ + return self._http.REQUEST_TIMEOUT # type: ignore + + # Setter for request_timeout + @request_timeout.setter + def request_timeout(self, value: Any) -> None: + self._http.REQUEST_TIMEOUT = value # type: ignore + def db( self, name: str = "_system", diff --git a/tests/test_client.py b/tests/test_client.py index 0a170b90..0b44faf2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -52,7 +52,12 @@ def test_client_attributes(): assert client.hosts == client_hosts assert repr(client) == client_repr assert isinstance(client._host_resolver, RandomHostResolver) - + + client = ArangoClient( + hosts=client_hosts, + request_timeout=120 + ) + assert client.request_timeout == client._http.REQUEST_TIMEOUT == 120 def test_client_good_connection(db, username, password): client = ArangoClient(hosts="http://127.0.0.1:8529") From d8f269d46c9a59a23a4569dab93bfc3e4b8cddf1 Mon Sep 17 00:00:00 2001 From: tjoubert Date: Fri, 5 Aug 2022 20:59:53 +0400 Subject: [PATCH 2/4] Fixed client constructor comments --- arango/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arango/client.py b/arango/client.py index ab04e5b1..382a1923 100644 --- a/arango/client.py +++ b/arango/client.py @@ -59,7 +59,7 @@ class ArangoClient: request timeout set in the http client. None: No timeout. int: Timeout value in seconds. - :type request_timeout: Optional[int] + :type request_timeout: Any """ def __init__( From 25d38b3fc2a251d8ebcc71946f61a67d309d0417 Mon Sep 17 00:00:00 2001 From: tjoubert Date: Fri, 5 Aug 2022 21:04:23 +0400 Subject: [PATCH 3/4] Formatted test_client.py --- tests/test_client.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 0b44faf2..1a6893b7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -52,13 +52,11 @@ def test_client_attributes(): assert client.hosts == client_hosts assert repr(client) == client_repr assert isinstance(client._host_resolver, RandomHostResolver) - - client = ArangoClient( - hosts=client_hosts, - request_timeout=120 - ) + + client = ArangoClient(hosts=client_hosts, request_timeout=120) assert client.request_timeout == client._http.REQUEST_TIMEOUT == 120 + def test_client_good_connection(db, username, password): client = ArangoClient(hosts="http://127.0.0.1:8529") From db551db23594c4450e1e332e278cb01949fe70a1 Mon Sep 17 00:00:00 2001 From: tjoubert Date: Mon, 15 Aug 2022 10:29:20 +0400 Subject: [PATCH 4/4] Request timeout is overwritten when a http_client is not specified. --- arango/client.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arango/client.py b/arango/client.py index 382a1923..7bdd6f4a 100644 --- a/arango/client.py +++ b/arango/client.py @@ -54,9 +54,8 @@ class ArangoClient: str: Path to a custom CA bundle file or directory. :type verify_override: Union[bool, str, None] :param request_timeout: This is the default request timeout (in seconds) - for http requests issued by the client. The default value is -1. - Setting this parameter to any other value, will overwrite your - request timeout set in the http client. + for http requests issued by the client if the parameter http_client is + not secified. The default value is 60. None: No timeout. int: Timeout value in seconds. :type request_timeout: Any @@ -71,7 +70,7 @@ def __init__( serializer: Callable[..., str] = lambda x: dumps(x), deserializer: Callable[[str], Any] = lambda x: loads(x), verify_override: Union[bool, str, None] = None, - request_timeout: Any = -1, + request_timeout: Any = 60, ) -> None: if isinstance(hosts, str): self._hosts = [host.strip("/") for host in hosts.split(",")] @@ -92,7 +91,7 @@ def __init__( self._http = http_client or DefaultHTTPClient() # Sets the request timeout. # This call can only happen AFTER initializing the http client. - if request_timeout != -1: + if http_client is None: self.request_timeout = request_timeout self._serializer = serializer