You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DocumentToImageContent still fails the whole batch with KeyError when a PDF page can't be converted #12911
Describe the bug
Since #12872, DocumentToImageContent returns None for an invalid document instead of failing the whole batch. This still doesn't work when a document points to a PDF page that can't be converted: the page is past the end of the PDF, or the PDF can't be read. _convert_pdf_to_images skips those pages and logs a warning, but _batch_convert_pdf_pages_to_images then looks them up with page_number_to_image[page_number] and raises a KeyError. The valid documents in the batch are lost too, including when it runs inside LLMDocumentContentExtractor.
Error message
KeyError: 99
File "haystack/components/converters/image/image_utils.py", line 337, in _batch_convert_pdf_pages_to_images
Expected behavior
The document gets None in image_contents and the others are still converted. That's what the run() docstring describes and what test_run_none_images expects. That test only passes because it mocks _batch_convert_pdf_pages_to_images to return {}.
Additional context
In practice this happens when stored documents point to a PDF that was later replaced with a shorter version, when a PDF is corrupted or only partly downloaded, or when a splitter assigns a page number past the end (see #12909).
Activity