Skip to content

Python: fix(core): handle None text safely in Message.text property - #8688

Closed
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/message-text-none-handling
Closed

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/message-text-none-handling

Conversation

@ManoharPaturi

Copy link
Copy Markdown
Contributor

Motivation & Context

In Message.text, the property concatenates text across all text content items via ' '.join(content.text for content in self.contents if content.type == 'text'). When a message contains a text content item whose text is None (e.g. created via Content('text', text=None) or parsed from a payload with null text), Python raises a TypeError: sequence item: expected str instance, NoneType found.

Filtering out None values ensures that message.text operates safely without crashing on null text content items, consistent with null text handling in Content.__str__ and from_function_result.

Description & Review Guide

  1. In Message.text in python/packages/core/agent_framework/_types.py, added and content.text is not None to the generator expression.
  2. Added unit test test_message_text_handles_none_text_contents in test_types.py verifying messages with null text content items return the concatenated string cleanly without raising TypeError.

Related Issue

None

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 23, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

Thank you for proposing this change. I am closing this PR for now because its Related Issue section says None, it has no linked issue, and I could not find an issue covering this specific problem. Your description uses the headings from the repository PR template, but its issue-link checklist item remains unchecked. The template asks for an issue linked with a closing keyword such as Fixes #123 and notes that PRs without an issue link may be closed. Our contribution guidelines ask contributors to create or reuse an issue and discuss the approach before nontrivial changes (with an exception for trivial changes). Please open or identify an issue, agree on the approach with the maintainers, then submit an updated PR using the template and linking the issue. Thanks.

This branch was previously deployed

1 inactive deployment
github-app-auth — 3ad20b46 Deployed Sep 23, 2026 by ManoharPaturi via team_check #5159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants