Skip to content

fix: MSGToDocument raises KeyError on ByteStream sources without file_path - #12207

Open
mittalpk wants to merge 1 commit into
deepset-ai:mainfrom
mittalpk:fix/msg-to-document-bytestream-keyerror
Open

fix: MSGToDocument raises KeyError on ByteStream sources without file_path#12207
mittalpk wants to merge 1 commit into
deepset-ai:mainfrom
mittalpk:fix/msg-to-document-bytestream-keyerror

Conversation

@mittalpk

Copy link
Copy Markdown

Related Issues

  • No existing issue filed; found via a direct code audit of MSGToDocument, not a bug report.

Proposed Changes

MSGToDocument.run() builds attachment metadata via merged_metadata["file_path"], but merged_metadata only contains "file_path" when the source was a str/Path (auto-populated by get_bytestream_from_source) or a ByteStream whose own meta happens to include it. A bare ByteStream(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 .msg file with attachments from such a source therefore raised an uncaught KeyError: 'file_path' instead of producing documents, crashing the whole run() call rather than just that one source.

Fixed by only setting parent_file_path on the attachment metadata when a source file_path is actually available, leaving it out otherwise instead of crashing.

How did you test it?

Reproduced the crash directly against main with a minimal script (MSGToDocument().run(sources=[ByteStream(data=open("test/test_files/msg/sample.msg","rb").read())])), confirmed the exact KeyError.

Added test_run_bytestream_without_file_path, confirmed it fails on unpatched msg.py (git stash) with the same KeyError, 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_path path changes, from an exception to a document/attachment without a parent_file_path key.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have added unit tests and updated the docstrings.
  • I've used a conventional commit type (fix:) for the PR title.
  • I have added a release note file.
  • I have run hatch run fmt / hatch run test:types / hatch run test:unit and 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.

…_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
mittalpk requested a review from a team as a code owner July 31, 2026 07:50
@mittalpk
mittalpk requested review from davidsbatista and removed request for a team July 31, 2026 07:50
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

@mittalpk is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants