From 420e3146b0db2caacd47fd2016e3551e429da201 Mon Sep 17 00:00:00 2001 From: Brooks Travis Date: Fri, 13 Feb 2026 01:10:08 -0600 Subject: [PATCH 1/3] Fix async HTTP client handling in BatchPoster class --- src/folio_data_import/BatchPoster.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/folio_data_import/BatchPoster.py b/src/folio_data_import/BatchPoster.py index 4e618ad..557f49f 100644 --- a/src/folio_data_import/BatchPoster.py +++ b/src/folio_data_import/BatchPoster.py @@ -331,6 +331,11 @@ async def __aenter__(self): self._failed_records_path, "w", encoding="utf-8" ) logger.info(f"Opened failed records file: {self._failed_records_path}") + if ( + not hasattr(self.folio_client, "async_httpx_client") + or self.folio_client.async_httpx_client is None + ): + self.folio_client.async_httpx_client = self.folio_client.get_folio_http_client_async() return self async def __aexit__(self, exc_type, exc_val, exc_tb): @@ -344,6 +349,11 @@ async def __aexit__(self, exc_type, exc_val, exc_tb): f"to {self._failed_records_path}" ) self._failed_records_file_handle = None + if ( + hasattr(self.folio_client, "async_httpx_client") + and not self.folio_client.async_httpx_client.is_closed + ): + await self.folio_client.async_httpx_client.aclose() def _write_failed_record(self, record: dict) -> None: """ From e26f182571a93b21cbba8ac83bb45ff1b91868a1 Mon Sep 17 00:00:00 2001 From: Brooks Travis Date: Fri, 13 Feb 2026 01:10:16 -0600 Subject: [PATCH 2/3] Fix HTTP client usage in UserImporter methods for improved API calls --- src/folio_data_import/UserImport.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/folio_data_import/UserImport.py b/src/folio_data_import/UserImport.py index 4017c46..c0e2891 100644 --- a/src/folio_data_import/UserImport.py +++ b/src/folio_data_import/UserImport.py @@ -242,7 +242,7 @@ async def do_import(self) -> None: This method triggers the process of importing users by calling the `process_file` method. Supports both single file path and list of file paths. """ - async with httpx.AsyncClient() as client: + async with self.folio_client.get_folio_http_client_async() as client: self.http_client = client if not self.config.user_file_paths: raise FileNotFoundError("No user objects file provided") @@ -274,7 +274,7 @@ async def get_existing_user(self, user_obj) -> dict: match_key = "id" if ("id" in user_obj) else self.config.user_match_key try: existing_user = await self.http_client.get( - self.folio_client.gateway_url + "/users", + "/users", headers=self.folio_client.okapi_headers, params={"query": f"{match_key}=={user_obj[match_key]}"}, ) @@ -298,7 +298,7 @@ async def get_existing_rp(self, user_obj, existing_user) -> dict: """ try: existing_rp = await self.http_client.get( - self.folio_client.gateway_url + "/request-preference-storage/request-preference", + "/request-preference-storage/request-preference", headers=self.folio_client.okapi_headers, params={"query": f"userId=={existing_user.get('id', user_obj.get('id', ''))}"}, ) @@ -322,7 +322,7 @@ async def get_existing_pu(self, user_obj, existing_user) -> dict: """ try: existing_pu = await self.http_client.get( - self.folio_client.gateway_url + "/perms/users", + "/perms/users", headers=self.folio_client.okapi_headers, params={"query": f"userId=={existing_user.get('id', user_obj.get('id', ''))}"}, ) @@ -489,7 +489,7 @@ async def update_existing_user( else: existing_user[key] = value create_update_user = await self.http_client.put( - self.folio_client.gateway_url + f"/users/{existing_user['id']}", + f"/users/{existing_user['id']}", headers=self.folio_client.okapi_headers, json=existing_user, ) @@ -509,7 +509,7 @@ async def create_new_user(self, user_obj) -> dict: HTTPError: If the HTTP request to create the user fails. """ response = await self.http_client.post( - self.folio_client.gateway_url + "/users", + "/users", headers=self.folio_client.okapi_headers, json=user_obj, ) @@ -719,7 +719,7 @@ async def create_new_rp(self, new_user_obj): rp_obj = {"holdShelf": True, "delivery": False} rp_obj["userId"] = new_user_obj["id"] response = await self.http_client.post( - self.folio_client.gateway_url + "/request-preference-storage/request-preference", + "/request-preference-storage/request-preference", headers=self.folio_client.okapi_headers, json=rp_obj, ) @@ -763,7 +763,7 @@ async def create_perms_user(self, new_user_obj) -> None: """ perms_user_obj = {"userId": new_user_obj["id"], "permissions": []} response = await self.http_client.post( - self.folio_client.gateway_url + "/perms/users", + "/perms/users", headers=self.folio_client.okapi_headers, json=perms_user_obj, ) @@ -910,7 +910,7 @@ async def get_existing_spu(self, existing_user): """ try: existing_spu = await self.http_client.get( - self.folio_client.gateway_url + "/service-points-users", + "/service-points-users", headers=self.folio_client.okapi_headers, params={"query": f"userId=={existing_user['id']}"}, ) @@ -934,7 +934,7 @@ async def create_new_spu(self, spu_obj, existing_user): """ spu_obj["userId"] = existing_user["id"] response = await self.http_client.post( - self.folio_client.gateway_url + "/service-points-users", + "/service-points-users", headers=self.folio_client.okapi_headers, json=spu_obj, ) @@ -953,7 +953,7 @@ async def update_existing_spu(self, spu_obj, existing_spu): """ # noqa: E501 existing_spu.update(spu_obj) response = await self.http_client.put( - self.folio_client.gateway_url + f"/service-points-users/{existing_spu['id']}", + f"/service-points-users/{existing_spu['id']}", headers=self.folio_client.okapi_headers, json=existing_spu, ) From 26cab99eb9f4389499610db4561f8786da7e9bb3 Mon Sep 17 00:00:00 2001 From: Brooks Travis Date: Fri, 13 Feb 2026 01:10:23 -0600 Subject: [PATCH 3/3] Bump version to 0.5.2 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4b85ce6..2414ccf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "folio_data_import" -version = "0.5.1" +version = "0.5.2" description = "A python module to perform bulk import of data into a FOLIO environment. Currently supports MARC and user data import." authors = [{ name = "Brooks Travis", email = "brooks.travis@gmail.com" }] license = "MIT"