From 4a118c166a52aa7393bf19ee25f88a63734b5cb1 Mon Sep 17 00:00:00 2001 From: yzbf <72718331+lin-wu-1990@users.noreply.github.com> Date: Wed, 28 May 2025 20:17:18 +0800 Subject: [PATCH] Fix overwriting existing init files in code generator (#637) --- backend/plugin/code_generator/service/gen_service.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/plugin/code_generator/service/gen_service.py b/backend/plugin/code_generator/service/gen_service.py index aba3e0d3..71c1d603 100644 --- a/backend/plugin/code_generator/service/gen_service.py +++ b/backend/plugin/code_generator/service/gen_service.py @@ -175,8 +175,9 @@ class GenService: code_folder.mkdir(parents=True, exist_ok=True) init_filepath = code_folder.joinpath('__init__.py') - async with aiofiles.open(init_filepath, 'w', encoding='utf-8') as f: - await f.write(gen_template.init_content) + if not os.path.exists(init_filepath): + async with aiofiles.open(init_filepath, 'w', encoding='utf-8') as f: + await f.write(gen_template.init_content) # api __init__.py if 'api' in str_code_filepath: