Skip to content

fix: skip non-string MIME metadata in DocumentTypeRouter - #12793

Closed
MohammadHijjawi97 wants to merge 3 commits into
deepset-ai:mainfrom
MohammadHijjawi97:fix/document-type-router-non-str-mime
Closed

MohammadHijjawi97 wants to merge 3 commits into
deepset-ai:mainfrom
MohammadHijjawi97:fix/document-type-router-non-str-mime

Conversation

@MohammadHijjawi97

@MohammadHijjawi97 MohammadHijjawi97 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Related Issues

No existing issue. This PR includes a regression test for the crash.

Proposed Changes:

DocumentTypeRouter passed mime_type metadata to re.fullmatch. A list or integer value raised TypeError. Treat non-string MIME metadata as missing and route those documents to unclassified. Also guard invalid file_path values when guessing MIME type: a non-empty value that is not a str/PathLike (e.g. a list of paths or an int) made Path(file_path) raise TypeError.

How did you test it?

  • Unit test for list, integer and None mime_type metadata next to a valid string.
  • Unit test for file_path metadata set to a list and an int next to a valid path: the valid one goes to text/plain, the others to unclassified. 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 --check clean.

Notes for the reviewer

The ValueError in except (TypeError, ValueError) covers Python 3.13+, where mimetypes.guess_type parses 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

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

re.fullmatch requires a string. List or integer mime_type metadata raised TypeError.
@MohammadHijjawi97
MohammadHijjawi97 requested a review from a team as a code owner September 17, 2026 11:05
@MohammadHijjawi97
MohammadHijjawi97 requested review from julian-risch and removed request for a team September 17, 2026 11:05
@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @MohammadHijjawi97, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 5 open pull requests in this repository (#12794, #12792, #12791, #12790 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @MohammadHijjawi97, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from julian-risch September 17, 2026 12:39
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Sep 17, 2026
@HaystackBot
HaystackBot marked this pull request as draft September 17, 2026 12:39
@HaystackBot
HaystackBot marked this pull request as ready for review September 19, 2026 08:51
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @MohammadHijjawi97! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Sep 19, 2026
@MohammadHijjawi97

Copy link
Copy Markdown
Contributor Author

CLA is signed now. This is ready for review whenever you have time.

@MohammadHijjawi97
MohammadHijjawi97 force-pushed the fix/document-type-router-non-str-mime branch from b4c934d to 76c9dea Compare September 25, 2026 08:30
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/routers
  document_type_router.py
Project Total  

This report was generated by python-coverage-comment-action

MohammadHijjawi97 and others added 2 commits October 1, 2026 14:56
List or integer file_path metadata makes Path() raise TypeError.
Check that those documents go to unclassified.
@MohammadHijjawi97

Copy link
Copy Markdown
Contributor Author

Hi @julian-risch, a short summary since you're assigned: I added a test for the file_path branch the coverage report flagged (a list or int file_path used to raise TypeError from Path(...); those documents now go to unclassified), so the router module is at 100% line coverage, and I just merged current main into the branch. The description has the before/after for both the mime_type and file_path cases. Happy to adjust anything.

@julian-risch

Copy link
Copy Markdown
Member

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.

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

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants