From c461261f0b693edd748f8f2eb66c9e046e2b2735 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Thu, 28 Aug 2025 09:35:29 +0800 Subject: [PATCH] Refactor: Improve the try logic for upload_to_minio (#9735) ### What problem does this PR solve? Improve the try logic for upload_to_minio ### Type of change - [x] Refactoring --- rag/svr/task_executor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rag/svr/task_executor.py b/rag/svr/task_executor.py index 078d4f296..e9151b70d 100644 --- a/rag/svr/task_executor.py +++ b/rag/svr/task_executor.py @@ -293,8 +293,7 @@ async def build_chunks(task, progress_callback): docs.append(d) return - output_buffer = BytesIO() - try: + with BytesIO() as output_buffer: if isinstance(d["image"], bytes): output_buffer.write(d["image"]) output_buffer.seek(0) @@ -317,8 +316,6 @@ async def build_chunks(task, progress_callback): d["image"].close() del d["image"] # Remove image reference docs.append(d) - finally: - output_buffer.close() # Ensure BytesIO is always closed except Exception: logging.exception( "Saving image of chunk {}/{}/{} got exception".format(task["location"], task["name"], d["id"]))