Skip to content

fix(knowledge): read PDF bytes via get_buffer for zip members - #7694

Closed
ump45nose wants to merge 1 commit into
1Panel-dev:mainfrom
ump45nose:fix/7436-zip-pdf-split
Closed

ump45nose wants to merge 1 commit into
1Panel-dev:mainfrom
ump45nose:fix/7436-zip-pdf-split

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

Fixes #7436.

Uploading a zip that only contains PDFs returned an empty split list with no server logs, while uploading the same PDF alone worked.

Root cause: PdfSplitHandle.handle read the file with UploadedFile.chunks(). Zip members are zipfile.ZipExtFile, which has no chunks(), so the call raised AttributeError. ZipSplitHandle then swallowed every exception with except Exception: pass, so PDF members were skipped silently.

Change:

  • Write the PDF temp file from get_buffer(file) (same path Doc/HTML/XLSX already use), which works for both UploadedFile and ZipExtFile.
  • Log zip-member split failures with max_kb.warning instead of silent pass.

Related prior attempt: #7448 (closed unmerged against an older impl/text/ layout).

Test plan

  • Local smoke of the temp-file write path with a raw buffer
  • Added apps/common/handle/impl/tests/test_pdf_zip_buffer.py (ZipExtFile-like object without chunks(); mocks fitz.open / TOC path)
  • Maintainers: upload a PDF-only zip in the knowledge UI and confirm paragraphs appear; check logs if a bad member fails

AI disclosure

This pull request was prepared with assistance from an autonomous coding agent (Grok Bot). I reviewed the diff and take responsibility for the change.

PdfSplitHandle used UploadedFile.chunks(), which ZipExtFile lacks.
ZipSplitHandle then swallowed the AttributeError, so PDF-only zip
uploads returned an empty split list with no logs. Write the buffer
from get_buffer instead, and log zip member split failures.

Fixes 1Panel-dev#7436
@ump45nose

Copy link
Copy Markdown
Contributor Author

Closing: opened against main by mistake. MaxKB default branch is v2, where PdfSplitHandle already uses hasattr(file, "chunks") + shutil.copyfileobj for zip members. Will re-check #7436 on v2 before opening a corrected PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant