hoprnet / hoprd-sdk-python

Native Python wrapper around the HOPR daemon API
3 stars 7 forks source link

ApiClient not cleaned up properly #22

Open jeandemeusy opened 1 year ago

jeandemeusy commented 1 year ago

The implementation of ApiClient in the file hoprd_sdk/api_client.py leaves a semaphore not cleaned-up after the instantiated ApiClient finishes his work. This behaviour is also documented here in OpenAPI/openapi-generator PR #5094

The following modification seams to solve this problem:

With the proposed modifications, one can and should use the ApiClient class within a context manager as in the following snippet:

from hoprd_sdk import Configuration, ApiClient
from hoprd_sdk.api import AccountApi

config = Configuration()
config.host = "dummy/host"
config.api_key["x-auth-token"] = "DuMmYt0k3n"

with ApiClient(config) as client:
    api = AccountApi(client)
    result = api.account_get_balance()

The main problem here is that the SDK is autogenerated, and for future version, doing this patch manually should be avoided.

In the new sdk v3, this solution has already been implemented. A long-term solution should by planned. Maybe using OpenAPI instead of Swagger can solve this.

Teebor-Choka commented 11 months ago

You can create a patch and apply it on each PR.