Skip to content

Commit 089915f

Browse files
committed
refactor: improve error logging for image reading and enhance image handling logic
--bug=1057749 --user=刘瑞斌 【知识库】qa问答对文档中带图片,导入后图片未显示 https://www.tapd.cn/62980211/s/1720856
1 parent 407fe83 commit 089915f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apps/common/handle/impl/common_handle.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
@desc:
88
"""
99
import io
10-
import logging
11-
12-
import uuid_utils.compat as uuid
10+
import traceback
1311
from functools import reduce
1412
from io import BytesIO
1513
from xml.etree.ElementTree import fromstring
1614
from zipfile import ZipFile
1715

16+
import uuid_utils.compat as uuid
1817
from PIL import Image as PILImage
1918
from openpyxl.drawing.image import Image as openpyxl_Image
2019
from openpyxl.packaging.relationship import get_rels_path, get_dependents
2120
from openpyxl.xml.constants import SHEET_DRAWING_NS, REL_NS, SHEET_MAIN_NS
2221

23-
from common.handle.base_parse_qa_handle import get_title_row_index_dict, get_row_value
2422
from common.utils.logger import maxkb_logger
2523
from knowledge.models import File
2624

@@ -76,7 +74,7 @@ def handle_images(deps, archive: ZipFile) -> []:
7674
image_io = archive.read(dep.target)
7775
image = openpyxl_Image(BytesIO(image_io))
7876
except Exception as e:
79-
maxkb_logger.error(f"Error reading image {dep.target}: {e}")
77+
maxkb_logger.error(f"Error reading image {dep.target}: {e}, {traceback.format_exc()}")
8078
continue
8179
image.embed = dep.id # 文件rId
8280
image.target = dep.target # 文件地址
@@ -107,6 +105,9 @@ def xlsx_embed_cells_images(buffer) -> {}:
107105
image_excel_id_list = [_xl for _xl in
108106
reduce(lambda x, y: [*x, *y], [sheet for sheet_id, sheet in sheet_list.items()], []) if
109107
key in _xl]
108+
# print(key, img)
109+
if img is None:
110+
continue
110111
if len(image_excel_id_list) > 0:
111112
image_excel_id = image_excel_id_list[-1]
112113
f = archive.open(img.target)

0 commit comments

Comments
 (0)