From 14140571d8374952bc64d09b3deb44c1eb3ced58 Mon Sep 17 00:00:00 2001 From: Dotty Dotter Date: Fri, 10 Apr 2026 20:05:28 +0200 Subject: [PATCH] Fix: CDU-PDF AssertionError Fallback + Kopfzeile vereinheitlicht + Fehler-Debug --- app/embeddings.py | 17 +++++++++++++++-- app/templates/index.html | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/embeddings.py b/app/embeddings.py index 894e6dc..117ea2b 100644 --- a/app/embeddings.py +++ b/app/embeddings.py @@ -649,7 +649,14 @@ def render_highlighted_page(programm_id: str, seite: int, query: str) -> Optiona needle = (query or "").strip()[:200] - src = fitz.open(str(pdf_path)) + try: + src = fitz.open(str(pdf_path)) + except Exception: + # Manche PDFs (z.B. CDU Grundsatzprogramm 2007) lassen sich nicht + # mit PyMuPDF öffnen. Fallback: Original-PDF ohne Highlighting. + logger.exception("render_highlighted_page: kann %s nicht öffnen", pdf_path.name) + return pdf_path.read_bytes(), seite, False + try: if seite < 1 or seite > len(src): return None, 0, False @@ -689,7 +696,13 @@ def render_highlighted_page(programm_id: str, seite: int, query: str) -> Optiona annot.update() highlighted = bool(needle and rects) - return src.tobytes(), target_page_idx + 1, highlighted + try: + return src.tobytes(), target_page_idx + 1, highlighted + except (AssertionError, Exception): + # PyMuPDF kann manche PDFs nicht serialisieren (z.B. CDU 2007). + # Fallback: Original-PDF ohne Annotations zurückgeben. + logger.warning("render_highlighted_page: tobytes() failed für %s, sende Original", pdf_path.name) + return pdf_path.read_bytes(), target_page_idx + 1, False finally: src.close() diff --git a/app/templates/index.html b/app/templates/index.html index 7e59272..0497239 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -699,10 +699,10 @@ + 📈 Auswertungen 📚 Quellen 🔍 Methodik - - 📈 Auswertungen +