fix(classifiers): guard against content=None in DocumentLanguageClassifier (fixes #11418)#11425
Closed
devteamaegis wants to merge 2 commits into
Closed
Conversation
|
@devteamaegis is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
|
Contributor
|
Closing as duplicate of #11419 |
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.
Summary
Fixes #11418 —
DocumentLanguageClassifiercrashes withTypeErrorwhen aDocumenthascontent=None.Before:
langdetect.detect(None)raisesTypeError, which is not caught by theLangDetectExceptionhandler. The exception propagates to the caller, crashing the pipeline. This affects any blob-onlyDocument(e.g. images, PDFs loaded without text extraction) sinceDocument.contentis explicitly allowed to beNone.After: an explicit
Noneguard is added before callinglangdetect.detect(). Documents withcontent=Nonelog a warning and returnNone(which causesrun()to route them to"unmatched"), consistent with existing behaviour for text thatlangdetectfails to detect.Changes
haystack/components/classifiers/document_language_classifier.pyif document.content is None:guard at the top of_detect_languageLangDetectExceptionbranch)Noneso the caller routes the document to"unmatched"test/components/classifiers/test_document_language_classifier.pyThree new tests:
test_content_none_does_not_raiserun([Document(content=None)])must not raise; document getslanguage="unmatched"test_content_none_emits_warningtest_mixed_none_and_text_contentNone-content doc and a text doc both classified correctlyTest plan
test_document_language_classifier.pypass:uv run --with langdetect --with pytest python -m pytest test/components/classifiers/test_document_language_classifier.py -v→10 passed