From eb76450cdc8fb53e7af9c860513737cac30e104c Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:51:08 +0800 Subject: [PATCH] fix: Exporting zip cannot open the file (#1939) --- apps/dataset/serializers/common_serializers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/dataset/serializers/common_serializers.py b/apps/dataset/serializers/common_serializers.py index 1cb33f88f..f908ca6bf 100644 --- a/apps/dataset/serializers/common_serializers.py +++ b/apps/dataset/serializers/common_serializers.py @@ -47,6 +47,8 @@ def write_image(zip_path: str, image_list: List[str]): if text.startswith('(/api/file/'): r = text.replace('(/api/file/', '').replace(')', '') file = QuerySet(File).filter(id=r).first() + if file is None: + break zip_inner_path = os.path.join('api', 'file', r) file_path = os.path.join(zip_path, zip_inner_path) if not os.path.exists(os.path.dirname(file_path)): @@ -56,6 +58,8 @@ def write_image(zip_path: str, image_list: List[str]): else: r = text.replace('(/api/image/', '').replace(')', '') image_model = QuerySet(Image).filter(id=r).first() + if image_model is None: + break zip_inner_path = os.path.join('api', 'image', r) file_path = os.path.join(zip_path, zip_inner_path) if not os.path.exists(os.path.dirname(file_path)):