Repository navigation
Conversation
PdfSplitHandle.handle read the file with file.chunks(), which only exists on Django UploadedFile. When a PDF arrives as a member of a zip archive it is a zipfile.ZipExtFile, so the call raised AttributeError, which ZipSplitHandle.handle swallowed without logging, and the split API returned an empty result for zips containing only PDFs. Read the buffer through the get_buffer abstraction that every other split handle already uses (it works for both UploadedFile and ZipExtFile), and log the member name and error instead of silently dropping it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7436
问题
上传只包含 PDF 的 zip 压缩包时,split 接口返回空数组、页面分段列表为空,且服务端没有任何错误日志;单独上传同一个 PDF 则一切正常。
根因
PdfSplitHandle.handle通过file.chunks()读取文件内容,而chunks()是 DjangoUploadedFile才有的方法。zip 内的 PDF 成员传入的是zipfile.ZipExtFile,没有chunks(),直接抛出AttributeError;该异常随后被ZipSplitHandle.handle里的except Exception: pass静默吞掉,于是压缩包内的 PDF 全部被跳过,split 返回空列表且无任何日志。修复
apps/common/handle/impl/text/pdf_split_handle.py:改用调用方注入的get_buffer读取文件(其余 6 个 split handle 均已使用该方式,对UploadedFile和ZipExtFile都有效),写入临时文件的逻辑不变。apps/common/handle/impl/text/zip_split_handle.py:压缩包成员解析失败时用maxkb_logger.warning记录 member 名与异常,不再静默吞掉,避免同类问题再次完全不可见。验证
ZipSplitHandle.handle走完整分派路径(仅 stub Django 胶水与无关注入,PDF 解析、zip 解包、分派逻辑均为仓库真实代码):[],无任何日志ruff check对两个改动文件无新增告警(get_file_name处的存量 F841 在 v2 上同样存在,与本次改动无关,未改动)。