Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when closing an async client. #2186

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .generator/src/generator/templates/api_client.j2
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ class AsyncApiClient(ApiClient):
raise exc
await self.rest_client._client.shutdown()

def close(self):
self.rest_client.close()

async def _call_api(
self,
method: str,
Expand Down
4 changes: 4 additions & 0 deletions .generator/src/generator/templates/rest.j2
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ class AsyncRESTClientObject:
self._client = aiosonic.HTTPClient(proxy=proxy, verify_ssl=configuration.verify_ssl)
self._configuration = configuration

def close(self):
# aiosonic doesn't close its clients
pass

def _retry(self, method, response, counter):
if (not self._configuration.enable_retry
or counter >= self._configuration.max_retries
Expand Down
3 changes: 3 additions & 0 deletions src/datadog_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ async def __aexit__(self, _exc_type, exc, _tb):
raise exc
await self.rest_client._client.shutdown()

def close(self):
self.rest_client.close()

async def _call_api(
self,
method: str,
Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def __init__(self, configuration):
self._client = aiosonic.HTTPClient(proxy=proxy, verify_ssl=configuration.verify_ssl)
self._configuration = configuration

def close(self):
# aiosonic doesn't close its clients
pass

def _retry(self, method, response, counter):
if (
not self._configuration.enable_retry
Expand Down
4 changes: 4 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ async def test_body():
api_instance = metrics_api.MetricsApi(api_client)
_, code, headers = await api_instance.submit_metrics(body=body)
assert code == 202


def test_close():
AsyncApiClient(Configuration()).close()
Loading