fix(review): warn (not debug) on shadow-classify failure; tidy pymupdf usage
Address PR #855 round 2: - 🔴 _shadow_classify swallowed all exceptions at DEBUG, so a systematic failure (pymupdf bug, memory pressure) is invisible at LOG_LEVEL=INFO and trips SonarQube S2221/S5754. Log at WARNING instead (still best-effort -- indexing is unaffected). - classifier: use `with pymupdf.open(...) as doc` instead of manual try/finally. - tests: release the Pixmap's native memory (del pix) in the image fixtures. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
0347e96679
commit
4bdb0bc6d6
@@ -113,8 +113,7 @@ def classify_pdf(content: bytes) -> DocClassification:
|
||||
"""
|
||||
import pymupdf # noqa: PLC0415 -- keep the heavy import lazy / off module load
|
||||
|
||||
doc = pymupdf.open("pdf", content)
|
||||
try:
|
||||
with pymupdf.open("pdf", content) as doc:
|
||||
page_count = doc.page_count
|
||||
indices = _sample_indices(page_count)
|
||||
pages: list[PageSignals] = []
|
||||
@@ -141,8 +140,6 @@ def classify_pdf(content: bytes) -> DocClassification:
|
||||
pages.append(
|
||||
PageSignals(n, len(text), round(coverage, 3), quality, needs_ocr)
|
||||
)
|
||||
finally:
|
||||
doc.close()
|
||||
|
||||
sampled = len(pages)
|
||||
total_chars = sum(p.char_count for p in pages)
|
||||
|
||||
Reference in New Issue
Block a user