Skip to content

fix(document-extractor): read document.xml when OPC relationships fail - #347

Open
leilei3167 wants to merge 1 commit into
langgenius:mainfrom
leilei3167:fix/issue-346-docx-opc-fallback
Open

leilei3167 wants to merge 1 commit into
langgenius:mainfrom
leilei3167:fix/issue-346-docx-opc-fallback

Conversation

@leilei3167

Copy link
Copy Markdown
Contributor

Important

  1. Contribution guidelines read. The change stays in the document extractor and its docx tests.
  2. Open issues and pull requests searched. No open pull request already changes these files.
  3. This pull request resolves the issue linked below.
  4. Conventional Commits title used. This is not a breaking change.
  5. The pull request title is suitable for the squash merge commit.
  6. CLA signature is not included in this pull request.

Related Issue

Closes #346

Summary

Document Extractor fails on Strict Open XML saves and on docx packages that omit _rels/.rels. python-docx raises KeyError because the package relationship is not the transitional officeDocument type. Rewriting ZIP entry paths does not repair that, and word/document.xml is still present.

When opening the package fails, read word/document.xml directly and return the same paragraph and markdown-table text a normal docx already produces. Packages python-docx can open are unchanged. A zip with no word/document.xml still raises TextExtractionError.

Before the change, test_extract_text_from_docx_reads_package_when_opc_relationships_fail failed for a strict relationship type, a strict wordprocessingml document, and a package without _rels/.rels. Each failure was TextExtractionError wrapping KeyError for the missing officeDocument relationship. After the change, that test and the rest of tests/nodes/document_extractor pass (54). ruff, ty, and the import-layer check pass.

Checklist

  • This pull request links the issue it resolves or advances
  • This pull request title follows Conventional Commits, and any breaking change is marked with !
  • If CLA Assistant prompted me, I signed CLA.md in the pull request conversation

python-docx rejects Strict Open XML packages and packages that omit
package relationships. Read word/document.xml after that failure so
paragraph and table text still comes back.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document Extractor: DOCX parsing fails with KeyError on 'officeDocument' relationship for Strict-OOXML saves / non-standard packages

1 participant