fix(workflow): add PDF extraction fallback#37525
Open
luochen211 wants to merge 1 commit into
Open
Conversation
6 tasks
Contributor
Pyrefly Type Coverage
|
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.
Summary
Fixes #37488.
The workflow Document Extractor can currently return a successful but empty result for some valid PDFs because Dify delegates PDF text extraction to Graphon 0.5.x, whose PDF extractor only uses PDFium. This PR installs a small Dify-side fallback during workflow node registration: keep Graphon/PDFium as the primary extractor, but when it returns only whitespace for
.pdf/application/pdf, retry the same bytes withpypdf.This keeps existing non-empty extraction behavior unchanged, adds
pypdfas a direct API dependency because Dify now imports it, and includes a unit test that patches the Graphon registry to reproduce the empty-PDFium case.Refs langgenius/graphon#189.
Screenshots
N/A, backend workflow extraction behavior.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods. Full command not run; scoped backend validation is listed below.Validation
uv lock --project api --checkuv run --project api pytest -o addopts='' api/tests/unit_tests/core/workflow/test_document_extractor_pdf_fallback.py api/tests/unit_tests/core/workflow/test_node_factory.py(52 passed)uv run --project api --group dev ruff format --check api/core/workflow/document_extractor_pdf_fallback.py api/core/workflow/node_factory.py api/tests/unit_tests/core/workflow/test_document_extractor_pdf_fallback.pyuv run --project api --group dev ruff check api/core/workflow/document_extractor_pdf_fallback.py api/core/workflow/node_factory.py api/tests/unit_tests/core/workflow/test_document_extractor_pdf_fallback.pyuv --directory api run pyrefly check core/workflow/document_extractor_pdf_fallback.py core/workflow/node_factory.py(0 errors; existing warnings innode_factory.py)uv --directory api run mypy core/workflow/document_extractor_pdf_fallback.py core/workflow/node_factory.py --check-untyped-defs --disable-error-code=import-untyped