Skip to content

fix: raise TypeError for non-string TextCleaner inputs - #12792

Merged
anakin87 merged 3 commits into
deepset-ai:mainfrom
MohammadHijjawi97:fix/text-cleaner-none-texts
Sep 24, 2026
Merged

anakin87 merged 3 commits into
deepset-ai:mainfrom
MohammadHijjawi97:fix/text-cleaner-none-texts

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

Related Issues

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

Proposed Changes:

Proposed Changes:

TextCleaner.run applied regex, lowercasing, and str.translate to every item. A None entry raised AttributeError. Coerce None and 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

  • 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.

TextCleaner applied regex, lower, and translate to every item. A None entry raised AttributeError.

Co-authored-by: Cursor <cursoragent@cursor.com>
@MohammadHijjawi97
MohammadHijjawi97 requested a review from a team as a code owner September 17, 2026 11:05
@MohammadHijjawi97
MohammadHijjawi97 requested review from anakin87 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.

@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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, #12793, #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.

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@MohammadHijjawi97

Copy link
Copy Markdown
Contributor Author

Thanks. Updated this to keep the list[str] contract: every element must be a str, otherwise it raises a clear TypeError. Tests updated accordingly.

@MohammadHijjawi97 MohammadHijjawi97 changed the title fix: treat None TextCleaner inputs as empty strings fix: raise TypeError for non-string TextCleaner inputs Sep 24, 2026
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Sep 24, 2026

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some little refinements.
Ready to be merged. Thanks!

@anakin87
anakin87 enabled auto-merge (squash) September 24, 2026 14:38
@anakin87
anakin87 merged commit d8dd477 into deepset-ai:main Sep 24, 2026
22 of 23 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/preprocessors
  text_cleaner.py
  haystack/core/pipeline
  pipeline.py
Project Total  

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

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