diff --git a/CHANGELOG.md b/CHANGELOG.md index b67204af..a2425157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `list_task_output_assets` and `get_task_output_asset` wait that the compute task is over before getting assets ([#369](https://github.com/Substra/substra/pull/369)) - warning and help message when logging in with username/password rather than token ([#378](https://github.com/Substra/substra/pull/378)) - new `Client.logout` function, mirroring `Client.login` ([#381](https://github.com/Substra/substra/pull/381)) -- `Client` can now be the expression in a `with` statement ([#381](https://github.com/Substra/substra/pull/381)) +- `Client` can now be used within a context manager ([#381](https://github.com/Substra/substra/pull/381)) + ```python + with Client( + client_name="org-1", + backend_type="remote", + url="http://substra-backend.org-1.com:8000", + username="org-1", + password="p@sswr0d44", + ) as client: + pass + ``` ### Changed diff --git a/substra/sdk/backends/remote/rest_client.py b/substra/sdk/backends/remote/rest_client.py index 406a073e..2b3a5e3c 100644 --- a/substra/sdk/backends/remote/rest_client.py +++ b/substra/sdk/backends/remote/rest_client.py @@ -111,7 +111,7 @@ def login(self, username, password): return token def logout(self) -> None: - if not self._token_id: + if self._token_id is None: return try: r = requests.delete( diff --git a/substra/sdk/client.py b/substra/sdk/client.py index 01eabf10..57f850bb 100644 --- a/substra/sdk/client.py +++ b/substra/sdk/client.py @@ -200,7 +200,7 @@ class Client: username (str, optional): Username to authenticate to the Substra platform. Used in conjunction with a password to generate a token if not given, using the `login` function. - If using username/password, you should use a context manager to ensure the session is terminated: + If using username/password, you should use a context manager to ensure the session terminates as intended: ``` with Client(username, password) as client: ...