diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb200f0..32119987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.14.2] - 2025-08-04 +### Fixed +- added back Api attributes removed in a previous release, this should fix potential breaking changes introduced in 1.14.1; + ## [1.14.1] - 2025-07-25 ### Added - Session mechanism for significantly decrease number of an http load on data-api for apps with intensive calling diff --git a/docs/antora-playbook.yml b/docs/antora-playbook.yml index 26c24511..ce83928a 100644 --- a/docs/antora-playbook.yml +++ b/docs/antora-playbook.yml @@ -7,7 +7,7 @@ content: start_path: docs branches: [] # branches: HEAD # Use this for local development - tags: [v1.14.1] + tags: [v1.14.2] asciidoc: attributes: page-toclevels: 5 diff --git a/docs/antora.yml b/docs/antora.yml index da9cec15..90a9e6a7 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,3 +1,3 @@ name: corva-sdk -version: ~ +version: 1.14.2 nav: [modules/ROOT/nav.adoc] diff --git a/src/corva/api.py b/src/corva/api.py index 333c19ba..a6ac7d79 100644 --- a/src/corva/api.py +++ b/src/corva/api.py @@ -7,6 +7,7 @@ from corva.api_utils import get_requests_session, get_retry_strategy from corva.configuration import SETTINGS +from corva.logger import CORVA_LOGGER class Api: @@ -16,6 +17,8 @@ class Api: convenient URL usage and reasonable timeouts to API requests. """ + TIMEOUT_LIMITS = (3, 30) # seconds + def __init__( self, *, @@ -24,20 +27,23 @@ def __init__( api_key: str, app_key: str, app_connection_id: Optional[int] = None, - max_retries: Optional[int] = 3, + max_retries: Optional[int] = 0, backoff_factor_retries: Optional[float] = 1, pool_conn_count: Optional[int] = None, pool_max_size: Optional[int] = None, pool_block: Optional[bool] = None, + timeout: Optional[int] = None, ): self.api_url = api_url self.data_api_url = data_api_url self.api_key = api_key self.app_key = app_key self.app_connection_id = app_connection_id + self.timeout = timeout or self.TIMEOUT_LIMITS[1] + self._max_retries = max_retries or SETTINGS.MAX_RETRY_COUNT self._session = get_requests_session( retry_strategy=get_retry_strategy( - max_retries=max_retries or SETTINGS.MAX_RETRY_COUNT, + max_retries=self._max_retries, backoff_factor=backoff_factor_retries or SETTINGS.BACKOFF_FACTOR, ), pool_connections_count=(pool_conn_count or SETTINGS.POOL_CONNECTIONS_COUNT), @@ -52,6 +58,22 @@ def default_headers(self): "X-Corva-App": self.app_key, } + @property + def max_retries(self) -> int: + return self._max_retries + + @max_retries.setter + def max_retries(self, value: int): + """ + max_retries are passed into Session object, so modifying it here won't have + any effect, raise warning and quit + """ + CORVA_LOGGER.warning( + "Do not modify max_retries attribute in existing object, create new Api " + "object with your custom max_retries param or set MAX_RETRY_COUNT env " + "variable in your environment" + ) + def get(self, path: str, **kwargs): return self._request("GET", path, **kwargs) @@ -113,6 +135,7 @@ def _execute_request( Returns: requests.Response instance. """ + _timeout = timeout or self.timeout return self._session.request( method=method, @@ -120,7 +143,7 @@ def _execute_request( params=params, json=data, headers=headers, - timeout=timeout, + timeout=_timeout, ) def _request( diff --git a/src/version.py b/src/version.py index ffeef941..ed0a4700 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -VERSION = "1.14.1" +VERSION = "1.14.2"