fix: MSGToDocument raises KeyError on ByteStream sources without file_path - #12207
Open
mittalpk wants to merge 1 commit into
Open
fix: MSGToDocument raises KeyError on ByteStream sources without file_path#12207mittalpk wants to merge 1 commit into
mittalpk wants to merge 1 commit into
Conversation
…_path MSGToDocument.run() built attachment metadata via merged_metadata["file_path"], but merged_metadata only contains "file_path" when the source is a path/str or a ByteStream whose meta happens to include it. A bare ByteStream(data=...) source -- an explicitly supported input type per the method's own signature, and the pattern shown in the class's own from_file_path-free examples elsewhere in the codebase -- has no such key, so converting a .msg file with attachments from such a source raised an uncaught KeyError instead of producing documents. Fixed by only setting parent_file_path on the attachment metadata when a source file_path is actually available.
|
@mittalpk is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
5 tasks
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.
Related Issues
MSGToDocument, not a bug report.Proposed Changes
MSGToDocument.run()builds attachment metadata viamerged_metadata["file_path"], butmerged_metadataonly contains"file_path"when the source was astr/Path(auto-populated byget_bytestream_from_source) or aByteStreamwhose ownmetahappens to include it. A bareByteStream(data=...)source — explicitly supported by the method's type signature (sources: list[str | Path | ByteStream]), and the exact pattern shown for other converters'ByteStream.from_string/manual-construction usage — has no such key. Converting a.msgfile with attachments from such a source therefore raised an uncaughtKeyError: 'file_path'instead of producing documents, crashing the wholerun()call rather than just that one source.Fixed by only setting
parent_file_pathon the attachment metadata when a sourcefile_pathis actually available, leaving it out otherwise instead of crashing.How did you test it?
Reproduced the crash directly against
mainwith a minimal script (MSGToDocument().run(sources=[ByteStream(data=open("test/test_files/msg/sample.msg","rb").read())])), confirmed the exactKeyError.Added
test_run_bytestream_without_file_path, confirmed it fails on unpatchedmsg.py(git stash) with the sameKeyError, and passes after the fix. Ran the full converters unit suite (hatch run test:unit test/components/converters/) — 263 passed, no regressions.hatch run test:types— no issues.hatch run fmt— clean.Notes for the reviewer
Small, behavior-preserving fix — no change for the existing (and already-tested) file-path-source path; only the previously-crashing
ByteStream-without-file_pathpath changes, from an exception to a document/attachment without aparent_file_pathkey.Checklist
fix:) for the PR title.hatch run fmt/hatch run test:types/hatch run test:unitand fixed any issue.This PR was developed with AI-assisted tooling (Claude Code); I reviewed the diagnosis, the fix, and the test, and ran the test suite and quality checks locally as noted above.