Repository navigation
fix: skip non-string MIME metadata in DocumentTypeRouter - #12793
MohammadHijjawi97 wants to merge 3 commits into
Conversation
re.fullmatch requires a string. List or integer mime_type metadata raised TypeError.
|
@MohammadHijjawi97 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @MohammadHijjawi97, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
|
Hi @MohammadHijjawi97, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thanks for signing the CLA, @MohammadHijjawi97! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
|
CLA is signed now. This is ready for review whenever you have time. |
b4c934d to
76c9dea
Compare
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
List or integer file_path metadata makes Path() raise TypeError. Check that those documents go to unclassified.
|
Hi @julian-risch, a short summary since you're assigned: I added a test for the |
|
Hi @MohammadHijjawi97 I am not aware of any Haystack component that writes a list or int into mime_type or file_path. So this guards against metadata shapes no Haystack component outputs and no user has reported this as an issue so far. It seems to hide malformed input too. Therefore, I'll close this PR. |
Related Issues
No existing issue. This PR includes a regression test for the crash.
Proposed Changes:
DocumentTypeRouterpassedmime_typemetadata tore.fullmatch. A list or integer value raisedTypeError. Treat non-string MIME metadata as missing and route those documents tounclassified. Also guard invalidfile_pathvalues when guessing MIME type: a non-empty value that is not astr/PathLike(e.g. a list of paths or an int) madePath(file_path)raiseTypeError.How did you test it?
Nonemime_typemetadata next to a valid string.file_pathmetadata set to a list and an int next to a valid path: the valid one goes totext/plain, the others tounclassified. It fails without the guard (TypeError: expected str, bytes or os.PathLike object, not list).test/components/routers/test_document_type_router.py: 23 passed; the router module is at 100% line coverage.ruff check/ruff format --checkclean.Notes for the reviewer
The
ValueErrorinexcept (TypeError, ValueError)covers Python 3.13+, wheremimetypes.guess_typeparses the path as a URL and raises for paths such as//[draft/notes.txt("Invalid IPv6 URL"). It is not tested because the behaviour differs by Python version.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.