Skip to content

Commit df7db0d

Browse files
jack-edmonds-ddci.datadog-api-spec
and
ci.datadog-api-spec
authored
Fix crash when closing an async client. (#2186)
* Fix crash when closing an async client. * pre-commit fixes --------- Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent b6fbe37 commit df7db0d

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

.generator/src/generator/templates/api_client.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ class AsyncApiClient(ApiClient):
574574
raise exc
575575
await self.rest_client._client.shutdown()
576576

577+
def close(self):
578+
self.rest_client.close()
579+
577580
async def _call_api(
578581
self,
579582
method: str,

.generator/src/generator/templates/rest.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ class AsyncRESTClientObject:
241241
self._client = aiosonic.HTTPClient(proxy=proxy, verify_ssl=configuration.verify_ssl)
242242
self._configuration = configuration
243243

244+
def close(self):
245+
# aiosonic doesn't close its clients
246+
pass
247+
244248
def _retry(self, method, response, counter):
245249
if (not self._configuration.enable_retry
246250
or counter >= self._configuration.max_retries

src/datadog_api_client/api_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ async def __aexit__(self, _exc_type, exc, _tb):
573573
raise exc
574574
await self.rest_client._client.shutdown()
575575

576+
def close(self):
577+
self.rest_client.close()
578+
576579
async def _call_api(
577580
self,
578581
method: str,

src/datadog_api_client/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ def __init__(self, configuration):
243243
self._client = aiosonic.HTTPClient(proxy=proxy, verify_ssl=configuration.verify_ssl)
244244
self._configuration = configuration
245245

246+
def close(self):
247+
# aiosonic doesn't close its clients
248+
pass
249+
246250
def _retry(self, method, response, counter):
247251
if (
248252
not self._configuration.enable_retry

tests/test_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ async def test_body():
7070
api_instance = metrics_api.MetricsApi(api_client)
7171
_, code, headers = await api_instance.submit_metrics(body=body)
7272
assert code == 202
73+
74+
75+
def test_close():
76+
AsyncApiClient(Configuration()).close()

0 commit comments

Comments
 (0)