Skip to content

fix(rag): close downloaded temp file before reopening it in WordExtractor - #39894

Open
AlexMultiAgent wants to merge 1 commit into
langgenius:mainfrom
AlexMultiAgent:fix/word-extractor-windows-temp-file
Open

fix(rag): close downloaded temp file before reopening it in WordExtractor#39894
AlexMultiAgent wants to merge 1 commit into
langgenius:mainfrom
AlexMultiAgent:fix/word-extractor-windows-temp-file

Conversation

@AlexMultiAgent

Copy link
Copy Markdown

fix(rag): close downloaded temp file before reopening it in WordExtractor

Fixes #39889

Summary

  • Close the NamedTemporaryFile handle immediately after writing the remote response so the path can be reopened on Windows.
  • Keep only the temp path on the instance and unlink it in close(); close() stays idempotent and tolerates a missing file.
  • Update the extractor unit tests to cover path-based cleanup (unlink, idempotency, missing-file tolerance) instead of handle closing.

Root cause

WordExtractor.__init__ downloads a remote .docx into tempfile.NamedTemporaryFile() and keeps the handle open. extract() reopens self.file_path through python-docx. On Windows, an open NamedTemporaryFile cannot be reopened by another handle (PermissionError, surfaced as PackageNotFoundError), so remote .docx extraction is broken on Windows. On Linux/macOS reopening works, which is why CI did not catch it.

Validation

  • Windows (Python 3.12): test_init_downloads_via_remote_fetcher now passes; WordExtractor(url).extract() returns parsed documents.
  • Backend: related test_word_extractor.py cases pass on Windows; unchanged behavior on POSIX.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Codex

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WordExtractor cannot extract remote .docx files on Windows (PermissionError: temp file is still open)

1 participant