From aa2a49abce30617aa5d720aa1e29a26841427240 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Wed, 3 Apr 2024 18:02:31 +0200 Subject: [PATCH] Make the delete method asynchronous in AsyncFirecrest --- firecrest/AsyncClient.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/firecrest/AsyncClient.py b/firecrest/AsyncClient.py index e518bb3..ccb63cf 100644 --- a/firecrest/AsyncClient.py +++ b/firecrest/AsyncClient.py @@ -357,7 +357,7 @@ async def _put_request( @_retry_requests # type: ignore async def _delete_request( self, endpoint, additional_headers=None, data=None - ) -> requests.Response: + ) -> httpx.Response: microservice = endpoint.split("/")[1] url = f"{self._firecrest_url}{endpoint}" async with self._locks[microservice]: @@ -369,10 +369,15 @@ async def _delete_request( headers.update(additional_headers) logger.info(f"Making DELETE request to {endpoint}") - # TODO: httpx doesn't support data in delete so we will have to - # keep using the `requests` package for this - resp = requests.delete( - url=url, headers=headers, data=data, timeout=self.timeout + # httpx doesn't support data in the `delete` method so we will have to + # use the generic `request` method + # https://www.python-httpx.org/compatibility/#request-body-on-http-methods + resp = await self._session.request( + method="DELETE", + url=url, + headers=headers, + data=data, + timeout=self.timeout, ) self._next_request_ts[microservice] = ( time.time() + self.time_between_calls[microservice]