Repository navigation
fix(rag): identify DOCX images by relationship type - #44905
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-10-30 04:38:56.044442066 +0000
+++ /tmp/pyrefly_pr.txt 2026-10-30 04:38:37.296468900 +0000
@@ -4303,7 +4303,7 @@
ERROR Object of class `NoneType` has no attribute `strip` [missing-attribute]
--> tests/unit_tests/core/rag/extractor/test_markdown_extractor.py:30:16
ERROR `_CloseRecorder` is not assignable to attribute `temp_file` with type `_TemporaryFileWrapper[bytes]` [bad-assignment]
- --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:397:27
+ --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:399:27
ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
--> tests/unit_tests/core/rag/index_processor/test_index_processor.py:240:16
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44905 +/- ##
===========================================
+ Coverage 68.68% 89.67% +20.98%
===========================================
Files 6083 6149 +66
Lines 367753 390569 +22816
Branches 77976 77656 -320
===========================================
+ Hits 252597 350238 +97641
+ Misses 112353 34029 -78324
- Partials 2803 6302 +3499
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JohnJyong
left a comment
There was a problem hiding this comment.
Reviewed the complete diff, relationship selection, internal/external image handling, storage/session ownership, and Markdown rendering. No issues found.
Validated on this head: 71 Word extractor and extraction-dispatch tests passed, including saved/reloaded DOCX files with image1.png, logo.png, and Logo.PNG, original stored image bytes, paragraph ordering, and rejection of non-image XML relationships. Ruff check and format check passed. Current backend unit, controller, integration, and Python-style CI checks are green.
Summary
Fixes #44904.
DOCX knowledge ingestion silently loses an embedded picture when its valid image relationship points to
media/logo.png, because the extractor requires the target name to containimage. The same name check also stores non-image XML parts whose target happens to contain that substring.Select image relationships by python-docx's
RT.IMAGEconstant. Existing storage, persistence, and Markdown rendering paths remain responsible for handling the selected images.Regression tests save and reload actual DOCX files, exercise
WordExtractor.extract()with real filesystem storage and SQLite sessions, and verify:image1.png,logo.png, andLogo.PNGproduce an image link in paragraph order and store the original PNG bytes.image-metadata.xmlcreates neither an image asset nor an UploadFile row.One additional lockfile metadata line is refreshed to match the existing dify-agent Pillow constraint. No locked package version changes. This is the same upstream stale metadata that the repository's autofix bot corrected on #44903; it prevents CI's lock check from failing before tests run.
Validation
image1.pngcontrol passes; the two alternative names and non-image relationship fail.make lint: passed, including all 75 import contracts.make type-check PATH_TO_CHECK=api/core/rag/extractor/word_extractor.py: passed.uv 0.13.6 lock --project api --checkandgit diff --check: passed.These results are local verification of the actual extractor and its dependencies, not a deployed knowledge-base ingestion or a remote CI result.
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods. (backend lint and scoped production type check; no frontend changes)AI assistance was used for investigation, implementation, and verification; the actual results and the pre-existing typing limitation are recorded above.
From Codex