fix: raise TypeError for non-string TextCleaner inputs - #12792
Conversation
TextCleaner applied regex, lower, and translate to every item. A None entry raised AttributeError. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@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. |
anakin87
left a comment
There was a problem hiding this comment.
Hello!
This component accepts list[str], so I would not silently accept and replace a None value.
What we can do instead is check whether every element in texts is a str and raise a clear TypeError if not.
Keep the list[str] contract: validate every element is a str and raise a clear TypeError instead of coercing None or other types.
|
Thanks. Updated this to keep the |
anakin87
left a comment
There was a problem hiding this comment.
I pushed some little refinements.
Ready to be merged. Thanks!
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
Related Issues
No existing issue. This PR includes a regression test for the crash.
Proposed Changes:
Proposed Changes:
TextCleaner.runapplied regex, lowercasing, andstr.translateto every item. ANoneentry raisedAttributeError. CoerceNoneand non-string items to empty strings so the output list keeps the same length.How did you test it?
Added a unit test covering
None, an integer, and mixed strings.Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.